I have two classes:
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class BaseConfiguratorServiceTest {
@Configuration
@ImportResource("/application-context.xml")
static class ContextConfiguration {
@Bean
public BaseConfiguratorService baseConfiguratorService() {
return new BaseConfiguratorService();
}
}
}
@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
public class AnotherTest {
@Configuration
@ImportResource("/application-context.xml")
static class AnotherConfiguration {
@Bean
public BaseConfiguratorService baseConfiguratorService() {
return new BaseConfiguratorService();
}
}
}
I am getting this error message:
Caused by: org.springframework.beans.factory.parsing.BeanDefinitionParsingException: Configuration problem: Only one AsyncAnnotationBeanPostProcessor may exist within the context.
Offending resource: class path resource [application-context.xml]
I don't know the reasoning. I am running one test at a time:
mvn test -Dtest=BaseConfiguraionTest
Then as the second class context is not loading at run time, why should spring care that another class has this annotation? Besides how does spring even know whether there is another class annotated with @Configuration.