Mastering Spring Boot 2.0
上QQ阅读APP看书,第一时间看更新

Disabling specific auto-configuration classes

At any point in time, if you don't want to use some of the specific auto-configuration classes or if they don't suit your needs, you can disable those auto-configuration classes. For this, you can use the exclude attribute of the @EnableAutoConfiguration annotation. Let's see the following example:

@EnableAutoConfiguration(exclude=DataSourceAutoConfiguration.class) 
public class ApplicationConfiguration { 
   ... 
} 

As per the code snippet, we have used the @EnableAutoConfiguration annotation with the exclude attribute. The DataSourceAutoConfiguration class will be excluded from the auto-configuration. Similarly, we can define a list of auto-configuration classes that need to be excluded.

You can define exclusions both at the annotation level and by using the property.

Let's move to another point of customizing auto-configuration in the Spring Boot application.