当前位置:首页 > 通信资讯 > 正文

springboot排除扫描包(springboot不扫描某个包)

启动类剔除扫描某个包

排除api中不引数据库导致的报错包

?
1 2 3 4 @ComponentScan(excludeFilters = { @ComponentScan.Filter(type = FilterType.REGEX,pattern = "com.integration.aop.log.service.*") })

通过该注解配置,可以实现剔除某个包,让Spring不自动扫描该包下的内容。

适用于依赖api或者其他包时,一些不必要或不支持的对象被扫描到,引发的报错或内存占用等问题。通过该配置可以去掉这些不必要的扫描。

使用正则表达式排除包扫描

?
1 2 3 4 5 // com.jiaobuchong.business 和 com.jiaobuchong.user.servic 下的类都不会被扫描 @ComponentScan(basePackages = {"com.jiaobuchong.order.service"}, excludeFilters = {@ComponentScan.Filter(type = FilterType.REGEX, pattern = "com.jiaobuchong.business\\..*"), @ComponentScan.Filter(type = FilterType.REGEX, pattern = "com.jiaobuchong.user.service\\..*")})

以上为个人经验,希望能给大家一个参考,也希望大家多多支持服务器之家。

原文链接:https://blog.csdn.net/hu18315778112/article/details/119727066

如果您对该产品感兴趣,请填写办理(客服微信:xiaoxiongyidong)

为您推荐:

发表评论

◎欢迎参与讨论,请在这里发表您的看法、交流您的观点。