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 ...

Get Mastering Spring Boot 2.0 now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.