一聚教程网:一个值得你收藏的教程网站

最新下载

热门教程

springboot启动类剔除扫描某个包代码示例

时间:2021-11-03 编辑:袖梨 来源:一聚教程网

本篇文章小编给大家分享一下springboot启动类剔除扫描某个包代码示例,文章代码介绍的很详细,小编觉得挺不错的,现在分享给大家供大家参考,有需要的小伙伴们可以来看看。

启动类剔除扫描某个包

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

热门栏目