봄 내에 테스트 수퍼 클래스가 설정 한 @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("one-off-test")
public class MyTest extends TestBase {
:
@ActiveProfiles("integration")
public abstract class 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
더 나은 것 것은 그렇지 주입, 즉 빈 그 사부 프로필
one-off-test
이있는 경우, 그래서 프로필을 레이어 할 수있는 무엇
integration
프로필 빈.
도움을 주시면 감사하겠습니다. 당신이 제시 한 문제에
아름답고 우아한 해결책 :
그럼 당신은 서브 클래스 프로파일을 discart 현재 주석 테스트 케이스를 방지 할 수
inheritProfiles
주석 propertytofalse
을 설정해야합니다. 고맙습니다! –당신이 그것을 좋아했기 때문에 기쁩니다 : -) !!! – geoand