Conflict with config class in dependency (Spring AsyncConfig)

388 views Asked by At

My team uses some starter code that's included in every internal Spring project by default. This is included as a dependency (not parent) in the pom.xml file of my project. This starter code contains a default implementation of a configuration interface which Spring does not allow duplicates of (AsyncConfigurer), but I need to create my own custom implementation. I am not sure how to resolve this. Is there a way for me to exclude this configuration class but keep the rest of the dependency? Or can I somehow keep the given config class, but modify its properties?

The specific exception I get is: java.lang.IllegalStateException: Only one AsyncConfigurer may exist

//Thank you

1

There are 1 answers

0
Felipe Bonfante On

You can define the AsyncConfigurer on parameter excludes from @SpringBootApplication. Example:

@SpringBootApplication(exclude=AsyncConfigurer.class)

Notice that this will excludes the entire @Configuration . Another solution is to use bean override, to define only the beans you need to replace. Add this to your application.properties (or yaml):

spring.main.allow-bean-definition-overriding=true

And you will be able to override it.