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

1 Answer

0 votes
by (1.7k points)
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

Share:- Whatsapp Facebook Facebook


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

Categories

...