springboot disable automatic configuration

In some cases (such as using mybatis, there is no need to load the datasource by default at startup) some automatic configuration features need to be disabled, which can be indicated by using the exclude attribute of the @EnableAutoConfiguration or @SpringBootApplication annotation.

For example, add a line in application.properties:

spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration

In this way, springboot will not automatically load datasource at startup, and will not report an error.

Or add a sentence to @SpringBootApplication at the springboot application run entry:

@EnableAutoConfiguration(exclude={DataSourceAutoConfiguration.class})

But in this way, idea will prompt an alarm, and the prompt is as follows:

Attributes should be specified via @SpringBootApplication less... (Ctrl+F1) 
Inspection info: Checks Spring Boot Application Setup.
@SpringBootApplication used in default package
Redundant @ComponentScan declaration
Redundant @EnableAutoConfiguration declaration
New in 2018.2

If you choose to add it to the configuration file, there will be no such prompt.

Guess you like

Origin blog.csdn.net/shaken/article/details/124579862