【Java】SpringBoot不扫描某个包 | 排除组件 | 排除类
·
一、假设
1、maven项目
2、SpringBoot项目
3、依赖了其他公共模块,需要将模块Service或Compont注册成Bean
4、依赖中的模块,不想扫描某个包或某些包(可能冲突)
二、解决: 启动类上增加注解
@ComponentScan(basePackages = {"cn.hg"},
excludeFilters = {
@ComponentScan.Filter(type = FilterType.REGEX, pattern = "ch.hg.oper.*")
,@ComponentScan.Filter(type = FilterType.REGEX, pattern = "ch.hg.pay.*")
})
示例图

更多推荐



所有评论(0)