有没有办法@ActiveProfile在Spring中覆盖测试超类的集合?
这是我的配置:
<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>
Run Code Online (Sandbox Code Playgroud)
所有测试的超类看起来像这样:
@ActiveProfiles("integration")
public abstract class TestBase {
Run Code Online (Sandbox Code Playgroud)
在我的新测试课中,我想这样做:
@ActiveProfiles("one-off-test")
public class MyTest extends TestBase {
Run Code Online (Sandbox Code Playgroud)
不继承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
Run Code Online (Sandbox Code Playgroud)
更好的是能够对配置文件进行分层,以便在存在用于配置文件 …