前言:
? ? ? ? 在最近工作中,相關業(yè)務代碼需要引用一個工具包。原來的同事在工具包中,封裝了Spring AOP切面的Bean,但是這樣的工具包非常不友好,工具包不應該有這些特殊的處理。有了這些特殊的處理,引用方也要特殊處理。
正文:
? ? ? ? 因為工具包中封裝了Spring切面bean,我首先想到在@SpringBootApplication注解中exclude屬性添加該類,但是報“The following classes could not be excluded because they are not auto-configuration classes:XXXXXXXX”錯誤。原因是:@SpringBootApplication注解的exclude只可以排除spring自動配置的bean。
? ? ? ? 經(jīng)過搜索資料,@ComponentScan注解的excludeFilters可以排除該bean,具體寫法如下:文章來源:http://www.zghlxwxcb.cn/news/detail-609515.html
@ComponentScan(value = "com.xxx",excludeFilters = {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,classes={Xxx.class})})
????????@ComponentScan注解的excludeFilters一個支持五種類型:FilterType.ANNOTATION:按照注解方式、FilterType.ASSIGNABLE_TYPE:按照指定類型的方式、FilterType.ASPECTJ:使用ASPECTJ表達式的方式、FilterType.REGEX:利用正則表達式方式、FilterType.CUSTOM:自己實現(xiàn)TypeFilter接口進行自定義規(guī)則。每種規(guī)則如何使用,請大家自行學習一下吧。文章來源地址http://www.zghlxwxcb.cn/news/detail-609515.html
到了這里,關于Springboot項目排除Bean的方法的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關文章,希望大家以后多多支持TOY模板網(wǎng)!