久久r热视频,国产午夜精品一区二区三区视频,亚洲精品自拍偷拍,欧美日韩精品二区

您的位置:首頁技術文章
文章詳情頁

springboot 啟動如何排除某些bean的注入

瀏覽:7日期:2023-02-20 15:01:17
springboot 啟動排除某些bean的注入問題:

最近做項目的時候,需要引入其他的jar。然后還需要掃描這些jar里的某些bean。于是使用注解:@ComponentScan

這個注解直接指定包名就可以,它會去掃描這個包下所有的class,然后判斷是否解析:

@ComponentScan(basePackages = {'your.pkg','other.pkg'})public class Application {} 

其他的jar中定義了 redissonConfig 這個bean。然后我自己的項目也定義了redissonConfig 這個bean。導致項目啟動報錯。所以使用如下方式,排除jar 中的RedissonConfig.class。

@ComponentScan(basePackages = {'com.xx.xx.*'}, excludeFilters =@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE, classes = {RedissonConfig.class}))@ComponentScan注解

掃描或解析的bean只能是Spring內部所定義的,比如@Component、@Service、@Controller或@Repository。如果有一些自定義的注解,比如@Consumer、這個注解修飾的類是不會被掃描到的。這個時候我們就得自定義掃描器完成這個操作。

配置文件中使用的:

component-scan標簽底層使用ClassPathBeanDefinitionScanner這個類完成掃描工作的。@ComponentScan注解配合@Configuration注解使用,底層使用ComponentScanAnnotationParser解析器完成解析工作。

springboot排除掃描包

@SpringBootApplication@ComponentScan(excludeFilters = { @ComponentScan.Filter(type = FilterType.REGEX,pattern = 'com.action.other.*') })public class Application { public static void main(String[] args) {SpringApplication.run(Application.class, args); }}

根據FilterType不同有不同的過濾方式,這里是根據正則過濾

以上為個人經驗,希望能給大家一個參考,也希望大家多多支持好吧啦網。

標簽: Spring
相關文章:
主站蜘蛛池模板: 茌平县| 奉化市| 哈巴河县| 舒兰市| 拜泉县| 崇州市| 乐至县| 曲阳县| 台北市| 泗洪县| 鹿泉市| 湘潭市| 临邑县| 沙河市| 涞水县| 池州市| 张家港市| 突泉县| 于都县| 高要市| 通榆县| 青岛市| 资溪县| 泰宁县| 海丰县| 萨迦县| 明水县| 台北市| 同江市| 丹棱县| 仁寿县| 革吉县| 张家口市| 桓仁| 彩票| 乌兰浩特市| 泗洪县| 进贤县| 宁德市| 同德县| 宁化县|