我正在尝试使用 Spock 和 Spring 创建一个简单的集成测试。所有必要的依赖项都存在于我的类路径中 - spock libs 和 spock-spring 。不幸的是,underTest
没有被注入(inject)(我总是得到java.lang.NullPointerException: Cannot invoke method someMethod() on null object
)。请看下面的代码
@ContextConfiguration(locations=["classpath:test1.xml","classpath:test2.xml"])
class SimpleSpockIntegrationTest extends Specification {
@Autowired
SomeRepo underTest;
@Transactional
def "repo test" () {
expected:
underTest.someMethod(1) == 1;
}
}
最佳答案
看起来 spock-spring 1.1 (1.1-groovy-2.4) 中可能存在错误
。切换到 1.0
后(使用 spock-core 1.1
时),一切正常。
关于java - @Autowired 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50424348/