Spring Boot 排除某個類加載注入IOC的操作
Spring Boot 排除某個類加載注入IOC
我們項目往往會引入其他項目的依賴,造成功能沖突的類,我們想把這些類排除掉,不注入到我們項目IoC容器中,
只加載自己的類
@ComponentScan(basePackages = "com.xxx",excludeFilters = { @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,classes = { xxxPublisher.class, xxxAdvice.class, xxxService.class})})
其中這三個類,我不需要加載到我們項目中,需要指明type=FilterType.ASSIGNABLE_TYPE
不指定type類型執(zhí)行classes={xxx...} 排除不了
它有五種類型:
public enum FilterType { ANNOTATION, ASSIGNABLE_TYPE, ASPECTJ, REGEX, CUSTOM; }
spring boot 排除個別配置類的代碼
廢話不說,直接上代碼
@SpringBootApplication(exclude={DataSourceAutoConfiguration.class,HibernateJpaAutoConfiguration.class}) @EnableScheduling @ComponentScan(basePackages = {"com.hudai.platform.sms.vendor","com.hudai.platform.scp"}, excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = com.hudai.platform.scp.alert.config.RestTemplateConfig.class)) public class SmsVendorApplication { public static void main(String[] args) { SpringApplication.run(SmsVendorApplication.class, args); } }
excludeFilters = @ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, value = com.hudai.platform.scp.alert.config.RestTemplateConfig.class))
這段是經(jīng)典~
以上為個人經(jīng)驗,希望能給大家一個參考,也希望大家多多支持腳本之家。
相關(guān)文章
詳解SpringBoot中JdbcTemplate的事務(wù)控制
JdbcTemplate是spring-jdbc提供的數(shù)據(jù)庫核心操作類,那對JdbcTemplate進行事務(wù)控制呢,本文就詳細的介紹一下2021-09-09springboot 如何解決static調(diào)用service為null
這篇文章主要介紹了springboot 如何解決static調(diào)用service為null的問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2021-06-06spring batch使用reader讀數(shù)據(jù)的內(nèi)存容量問題詳解
這篇文章主要介紹了spring batch使用reader讀數(shù)據(jù)的內(nèi)存容量問題詳解,文中通過示例代碼介紹的非常詳細,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2020-07-07java socket實現(xiàn)聊天室 java實現(xiàn)多人聊天功能
這篇文章主要為大家詳細介紹了java socket實現(xiàn)聊天室,java實現(xiàn)多人聊天功能,文中示例代碼介紹的非常詳細,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-07-07Java按照List內(nèi)存儲的對象的某個字段進行排序的實例
下面小編就為大家?guī)硪黄狫ava按照List內(nèi)存儲的對象的某個字段進行排序的實例。小編覺得挺不錯的,現(xiàn)在就分享給大家,也給大家做個參考。一起跟隨小編過來看看吧2016-12-12