1

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.

user1539343
  • 1,569
  • 6
  • 28
  • 45

1 Answers1

0

I'm having the same problem as you and although I'm still not sure why it happens, I found that this answer solved my (our) problem: https://stackoverflow.com/a/39307385/1410035

I'm using @WebAppConfiguration (which the answer addresses) but hopefully it'll still be applicable for your situation.

I'm on Spring 4.2.x FWIW. Also, that linked answer is from an author of the Spring code in question so we can probably trust it.

Tom Saleeba
  • 4,031
  • 4
  • 41
  • 36