Share:- Whatsapp Facebook Facebook

------------------------------------- Welcome to Developerhelpway Q&A, where you can ask questions and receive answers from other members of the community.

How to disable a specific auto-configuration?

0 votes
3 views
How to disable a specific auto-configuration?
asked Feb 10 in Spring Boot by RAHUL YADAV

1 Answer

0 votes
If we want to disable a specific auto-configuration in spring boot, we can exclude attribute of the @EnableAutoConfiguration annotation. See the following code snippet neutralizes DataSourceAutoConfiguration:
//annotations
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
public class MyConfiguration { }
   
//annotations
@EnableAutoConfiguration(exclude = DataSourceAutoConfiguration.class)
public class MyConfiguration { }

If we can enable auto-configuration with the @SpringBootApplication annotation. @SpringBootApplication annotation has @EnableAutoConfiguration as a meta-annotation. We could disable auto-configuration with an attribute of the same name:
//annotations
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class MyConfiguration { }
   
//annotations
@SpringBootApplication(exclude = DataSourceAutoConfiguration.class)
public class MyConfiguration { }

We can also disable an auto-configuration with the spring.autoconfigure.exclude environment property. This configuration in the application.properties file does the same thing as before:
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
answered 4 days ago by Developerhelpway (1,520 points)
...