Share:- Whatsapp Facebook Facebook

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

Categories

0 votes
11 views
How to disable a specific auto-configuration?
in Spring Boot by

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
by (1.6k points)
...