好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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

查看更多关于springboot启动类如何剔除扫描某个包的详细内容...

  阅读:12次