Python 官方文档:入门教程 => 点击学习
Spring Boot 排除自动配置 方法1 使用 @SpringBootApplication 注解,用 exclude 属性进行排除指定的类: @springBootAppl
使用 @SpringBootApplication 注解,用 exclude 属性进行排除指定的类:
@springBootApplication(exclude = {DataSourceAutoConfiguration.class})
public class Application {
// ...
}
单独使用 @EnableAutoConfiguration 注解的时候:
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
public class Application {
// ...
}
使用 @SpringCloudApplication 注解的时候:
@EnableAutoConfiguration(exclude = {DataSourceAutoConfiguration.class})
@SprinGCloudApplication
public class Application {
// ...
}
终极方案,不管是 Spring Boot 还是 spring cloud 都可以搞定,在配置文件中指定参数 spring.autoconfigure.exclude 进行排除:
spring.autoconfigure.exclude=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
或者还可以这样写:
spring.autoconfigure.exclude[0]=org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
yml 配置文件:
spring:
autoconfigure:
exclude:
- org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration
新建了一个springboot工程,运行程序时报错:Reason: Failed to determine a suitable driver class
问题原因: 新工程中未进行数据源信息配置。如果去掉springboot工程相关自动配置,该问题就不会出现了
@SpringBootApplication(exclude = { DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class })
public class UmeapiPlusApplication {
public static void main(String[] args) {
SpringApplication.run(UmeApiPlusApplication.class, args);
}
}
使用@SpringBootApplication(exclude = {})可去除springboot工程的自动配置。
以上为个人经验,希望能给大家一个参考,也希望大家多多支持编程网。
--结束END--
本文标题: 基于Spring Boot 排除自动配置的4个方法
本文链接: https://www.lsjlt.com/news/131628.html(转载时请注明来源链接)
有问题或投稿请发送至: 邮箱/279061341@qq.com QQ/279061341
下载Word文档到电脑,方便收藏和打印~
2024-03-01
2024-03-01
2024-03-01
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
2024-02-29
回答
回答
回答
回答
回答
回答
回答
回答
回答
回答
0