样例:
引入的依赖包含jdbc, druid连接池, mybatis依赖,需要排除三个启动类
1. 在主启动类添加SpringBootApplication注解
@SpringBootApplication(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class, MybatisAutoConfiguration.class})
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@SpringBootApplication (exclude = exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class, MybatisAutoConfiguration.class})
public class OrderMain80 {
public static void main(String[] args) {
SpringApplication.run(OrderMain80.class,args);
}
}
2.使用@EnableAutoConfiguration注解
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class, MybatisAutoConfiguration.class}) 注解
注意: 使用了该注解后不要再使用@SpringBootApplication注解,因为@SpringBootApplication注解包含@EnableAutoConfiguration注解
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class, DruidDataSourceAutoConfigure.class, MybatisAutoConfiguration.class} )
public class OrderMain80 {
public static void main(String[] args) {
SpringApplication.run(OrderMain80.class,args);
}
}
3. 在配置文件中排除
1. yaml文件
#springboot排除自动配置
spring:
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
- com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
- org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration
2. properties文件
spring.autoconfigure.exclude[0]=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
spring.autoconfigure.exclude[1]=com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure
spring.autoconfigure.exclude[2]=org.mybatis.spring.boot.autoconfigure.MybatisAutoConfiguration