spring boot EnableAutoConfiguration exclude 無效


 本文鏈接:https://blog.csdn.net/ID19870510/article/details/79373386

首先講一下SpringBootApplication注解
源碼定義為

@Target(ElementType.TYPE)
@Retention(RetentionPolicy.RUNTIME)
@Documented
@Inherited
@SpringBootConfiguration
@EnableAutoConfiguration
@ComponentScan(excludeFilters = {
		@Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
		@Filter(type = FilterType.CUSTOM, classes = AutoConfigurationExcludeFilter.class) })
public @interface SpringBootApplication {

所以這一個注解就相當於配置了EnableAutoConfiguration
如果在自己的項目里 SpringBootApplication 和 EnableAutoConfiguration 都配置了 就會有問題。這個是我最開始的理解
但是試了一下 把SpringBootApplication去掉 然后改成如下的形式 還是不行

// @SpringBootApplication
@EnableTransactionManagement // 開啟注解式事務 , DataSourceTransactionManagerAutoConfiguration.class
@EnableAutoConfiguration(exclude = { DataSourceAutoConfiguration.class, DataSourceTransactionManagerAutoConfiguration.class, HibernateJpaAutoConfiguration.class })
@EnableAspectJAutoProxy(proxyTargetClass = true, exposeProxy = true)
@Configuration
@ComponentScan(includeFilters={}, excludeFilters = { @Filter(type = FilterType.CUSTOM, classes = TypeExcludeFilter.class),
		@Filter(type = FilterType.CUSTOM, classes =  AutoConfigurationExcludeFilter.class)})
// @ComponentScan
// @Configuration //這是一個配置類,與@Service、@Component的效果類似。spring會掃描到這個類,@Bean才會生效,將ThreadPoolBean這個返回值類注冊到spring上下文環境中
// @EnableConfigurationProperties(MyWebServerConfigurationProperties.class) //通過這個注解, 將MyWebServerConfigurationProperties這個類的配置到上下文環境中,本類中使用的@Autowired注解注入才能生效
public class  XxxApplication extends BaseApplication {

 

網上查資料 最終的解決辦法如下

spring:
  application:
    name: coffee
  autoconfigure.exclude: org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration, org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration
 

具體原因還沒找到,先記錄一下 ,以后在查找原因


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM