Spring Boot - Turn off specific auto-configuration classes

Turn off specific auto-configuration classes

In Spring Boot, if you want to turn off a specific auto-configuration class, you can use the exclude attribute of the @EnableAutoConfiguration annotation to exclude the specified auto-configuration class.

@SpringBootApplication(exclude = ErrorMvcAutoConfiguration.class)
public class SpringbootStudy2023Application {

    public static void main(String[] args) {
        SpringApplication.run(SpringbootStudy2023Application.class, args);
    }

}

In the above example, we used the @SpringBootApplication annotation and specified the automatic configuration class ErrorMvcAutoConfiguration to be turned off in the exclude attribute. This will disable Spring
Boot's auto-configuration of error handling.

You can add other automatic configuration classes to be turned off in the exclude attribute according to your own needs. Just list the class names of the auto-configuration classes you want to exclude in the exclude attribute.

In addition, you can also use the spring.autoconfigure.exclude property to configure the auto-configuration classes to be turned off in the application.properties (or application.yml) file. Examples are as follows:

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.security.servlet.SecurityAutoConfiguration

The above configuration will turn off security auto-configuration in Spring Boot.

Guess you like

Origin blog.csdn.net/qq_43116031/article/details/131029574