我试图向现有的项目中添加一些groovy脚本,并坚持使集成测试工作正常。我有几个用<qualifier />标记的bean,它们用于测试和生产代码中的自动装配。
就在我将'org.codehaus.groovy: groovy -all:2.4.0‘添加到依赖项之后,即使没有任何groovy用法,我的集成测试也会停止工作,除非:
SEVERE: Caught exception while allowing TestExecutionListener [org.springframework.test.context.support.DependencyInjectionTestExecutionListener@5e5f7983] to prepare test instance [com.dph.groovy.vs.springtest.IntegrationTest@299c9fe7]
java.lang.IllegalStateException: Failed to load ApplicationContext
at org.springframework.test.context.DefaultCacheAwareContextLoaderDelegate.loadContext(DefaultCacheAwareContextLoaderDelegate.java:94)
at org.springframework.test.context.DefaultTestContext.getApplicationContext(DefaultTestContext.java:72)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.injectDependencies(DependencyInjectionTestExecutionListener.java:117)
at org.springframework.test.context.support.DependencyInjectionTestExecutionListener.prepareTestInstance(DependencyInjectionTestExecutionListener.java:83)
at
......
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Unexpected failure during bean definition parsing
Offending resource: class path resource [spring/app-config.xml]
Bean 'service'; nested exception is org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Tag 'qualifier' must have a 'type' attribute
Offending resource: class path resource [spring/app-config.xml]
Bean 'service'
at org.springframework.beans.factory.parsing.FailFastProblemReporter.error(FailFastProblemReporter.java:70)
at org.springframework.beans.factory.parsing.ReaderContext.error(ReaderContext.java:85)
at org.springframework.beans.factory.xml.BeanDefinitionParserDelegate.error(BeanDefinitionParserDelegate.java:323)但是,运行项目(如果这很重要的话使用jetty 6)不会引起任何问题,所以我认为spring测试联合和groovy有一些技巧。
我可能只是在限定符中添加“type”,但这并不能解决问题,因为我的外部依赖项具有相同的限定符标记配置,而且据我所知,这个属性是可选的。
我想至少找出这个问题的根源。
我创建了一个示例项目来重现所描述的问题,并将欣赏任何想法:https://github.com/ametiste/groovy-vs-spring-test
发布于 2015-02-28 17:25:57
您已经在Spring的测试支持中发现了一个bug。
固定在SpringFramework4.1.6和4.2 RC1中
我已经修复了SpringFramework4.1.6(计划在2015年3月底发布)和4.2 (计划在Q3 2015年发布)的这个bug。有关详细信息,请参阅JIRA发行版SPR-12768。
如果希望在上述版本之前尝试修复,请考虑使用即将发布的夜间快照之一进行构建。
临时工作-环绕
同时,(对于允许编辑的XML配置文件),您可以通过显式地将<qualifier>标记中的<qualifier>属性设置为预期的默认值(即"org.springframework.beans.factory.annotation.Qualifier" )来规避该错误。有关示例,请参见下面的XML配置。
<bean id="foo" class="java.lang.String" c:_="bar">
<qualifier value="foo" type="org.springframework.beans.factory.annotation.Qualifier" />
</bean>致以敬意,
Sam ( Spring TestContext框架的作者)
https://stackoverflow.com/questions/28212993
复制相似问题