[英]@Autowired doesn't work
I am trying to create a simple integration test using Spock and Spring. 我正在尝试使用Spock和Spring创建一个简单的集成测试。 All the necessary dependencies are present in my classpath - spock libs and spock-spring
. 所有必需的依赖项都存在于我的classpath-spock库和spock-spring
。 Unfortunately, underTest
is not being injected (I always get java.lang.NullPointerException: Cannot invoke method someMethod() on null object
). 不幸的是,未注入underTest
(我总是得到java.lang.NullPointerException: Cannot invoke method someMethod() on null object
)。 Please see below code 请看下面的代码
@ContextConfiguration(locations=["classpath:test1.xml","classpath:test2.xml"])
class SimpleSpockIntegrationTest extends Specification {
@Autowired
SomeRepo underTest;
@Transactional
def "repo test" () {
expected:
underTest.someMethod(1) == 1;
}
}
Looks like there might be a bug in spock-spring 1.1 (1.1-groovy-2.4)
. 看起来spock-spring 1.1 (1.1-groovy-2.4)
可能存在错误。 After switching to 1.0
(while using spock-core 1.1
) everything works perfectly. 切换到1.0
(使用spock-core 1.1
),一切正常。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.