欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

springboot启动类如何剔除扫描某个包

程序员文章站 2022-07-05 09:44:05
启动类剔除扫描某个包排除api中不引数据库导致的报错包@componentscan(excludefilters = { @componentscan.fi...

启动类剔除扫描某个包

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

@componentscan(excludefilters =
        {
                @componentscan.filter(type = filtertype.regex,pattern = "com.integration.aop.log.service.*")
        })

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

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

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

// 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\\..*")})

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