Java 如何让Roo集成测试与AnnotationConfigContextLoader一起工作
我使用基于XML的spring配置和spring 3.1运行roo生成的集成测试已经有相当一段时间了。然而,我最近从基于XML的配置更改为基于java的配置,并从Spring3.1升级到Spring4.0 不幸的是,我的roo genenerated集成测试现在失败,出现以下异常:Java 如何让Roo集成测试与AnnotationConfigContextLoader一起工作,java,spring,spring-roo,Java,Spring,Spring Roo,我使用基于XML的spring配置和spring 3.1运行roo生成的集成测试已经有相当一段时间了。然而,我最近从基于XML的配置更改为基于java的配置,并从Spring3.1升级到Spring4.0 不幸的是,我的roo genenerated集成测试现在失败,出现以下异常: java.lang.IllegalStateException: Test class [com.bulb.learn.domain.CounterIntegrationTest] has been configur
java.lang.IllegalStateException: Test class [com.bulb.learn.domain.CounterIntegrationTest] has been configured with @ContextConfiguration's 'locations' (or 'value') attribute {classpath*:/META-INF/spring/applicationContext*.xml}, but AnnotationConfigContextLoader does not support resource locations.
at org.springframework.test.context.support.AnnotationConfigContextLoader.validateMergedContextConfiguration(AnnotationConfigContextLoader.java:164)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:111)
at org.springframework.test.context.support.AbstractGenericContextLoader.loadContext(AbstractGenericContextLoader.java:60)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContextInternal(CacheAwareContextLoaderDelegate.java:64)
at org.springframework.test.context.CacheAwareContextLoaderDelegate.loadContext(CacheAwareContextLoaderDelegate.java:91)
... 32 more
我知道这是由roo生成的方面文件中的这一行引起的:
declare @type: CounterIntegrationTest: @ContextConfiguration(locations = "classpath*:/META-INF/spring/applicationContext*.xml");
这是因为我将其用于我的主要测试类基类:
@RunWith(SpringJUnit4ClassRunner.class)
@ActiveProfiles(profiles = "junit")
@ContextConfiguration(classes = { CoreConfig.class }, loader = AnnotationConfigContextLoader.class)
public abstract class CoreIntegrationTest {
...
}
下面是我如何定义@RooIntegrationTest注释的类
@RooIntegrationTest(entity = Counter.class, transactional = false)
public class CounterIntegrationTest extends CoreIntegrationTest {
然而,我不知道如何修复它
roo测试过去运行良好。只要升级到Spring4.0,它们也可以正常运行。只需更改Spring3.1的java配置,它们也可以正常运行。但是,它们不能同时使用(Spring4.0和Java配置)
有没有人知道我如何让它们工作,而不是简单地将它们从roo控制中移除,并自己移除违规线路
提前谢谢 结果是,Roo在向方面添加一个注释类之前,会查看注释类是否已经有了
@ContextConfiguration
。不幸的是,它没有检查是否继承了@ContextConfiguration
我通过向注释类添加默认的@ContextConfiguration
解决了这个问题,如下所示:
@ContextConfiguration
@RooIntegrationTest(entity = Counter.class, transactional = false)
public class CounterIntegrationTest extends CoreIntegrationTest {
这会阻止Roo生成自己的,因此错误会消失