我遇到了一个问题,我为我的源代码创建了配置类,并为我的测试包创建了单独的配置类。我想要一些在测试中创建的bean比在其他环境中创建的不同。然而,当我运行构建这里发生了什么:(我有一个bean叫文件系统,它给了我一个虚拟文件系统测试)通过常规配置覆盖测试中的弹簧配置
Overriding bean definition for bean 'fileSystem' with a different definition: replacing <testVersion from MockAppInjector> with <realVersionFromAppInjector>
我在我的测试包我有
@Configuration
@ImportResource("classpath:/META-INF/fig-batch/spring-bootstrap.xml")
@ComponentScan(basePackages = "com.company")
class MockAppInjector {...}
,并在我的定期源码包我有
@Configuration
@ImportResource("classpath:/META-INF/fig-batch/spring-bootstrap.xml")
@ComponentScan(basePackages = "com.company")
public class AppInjector {...}
而在我的测试中,我有@ContextConfiguration(classes = MockAppInjector.class)
最后,我所有的xml文件都是<context:component-scan base-package="com.company" />
,并调用另一个配置一些数据源的xml。
被覆盖的bean没有在xml中定义,只在我的其他@Configuration类中定义。是否有可能我的xml找到了我的其他配置,因为组件扫描,并且*是*是什么导致覆盖? – Steve
@Steve是可能的,但请更具体一些:您的产品类位于何处,它被实例化为bean,您的测试类位于何处以及它作为bean实例化的位置? –