有没有办法在Spring中覆盖由测试超类设置的@ActiveProfile
?在Spring框架中覆盖或覆盖ActiveProfiles
这里是我的配置:
<beans profile="integration">
<bean class="org.easymock.EasyMock" factory-method="createMock">
<constructor-arg value="com.mycompany.MyInterface" />
</bean>
</beans>
<beans profile="production,one-off-test">
<bean class="com.mycompany.MyInterfaceImpl" />
</beans>
超类中的所有测试看起来是这样的:
@ActiveProfiles("integration")
public abstract class TestBase {
而且在我的新测试类,我想这样做:
@ActiveProfiles("one-off-test")
public class MyTest extends TestBase {
不从TestBase继承不是一个真正的选择。 当我尝试运行它,我得到的错误是:
No qualifying bean of type [com.mycompany.MyInterface] is defined: expected single matching bean but found 2
Caused by: org.springframework.beans.factory.NoUniqueBeanDefinitionException: No qualifying bean of type [com.mycompany.MyInterface] is defined: expected single matching bean but found 2: org.easymock.EasyMock#1,com.mycompany.MyInterfaceImpl#0
at org.springframework.beans.factory.support.DefaultListableBeanFactory.doResolveDependency(DefaultListableBeanFactory.java:970)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.resolveDependency(DefaultListableBeanFactory.java:858)
at org.springframework.beans.factory.annotation.AutowiredAnnotationBeanPostProcessor$AutowiredFieldElement.inject(AutowiredAnnotationBeanPostProcessor.java:480)
... 46 more
什么是更好的是要能够层剖面,所以如果一个bean存在轮廓one-off-test
注射的是那个,否则注入integration
配置文件bean。
任何帮助将不胜感激。
美丽和优雅的解决方案。谢谢! – 2014-09-06 00:00:34
我很高兴你喜欢它: - )!!! – geoand 2014-09-06 06:26:07