有沒有辦法在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