一、说明

1、项目依赖其他子模块

2、子模块中做了一些自动注入的配置,比如@Component,@Configuration,甚至@Service

3、但是呢,想用到子模块的utils,不想用自动注入的服务

二、解决方案

在main方法所在类增加注解

1、排除类

@ComponentScan(basePackages = {"cn.hg", "cn.hutool"},excludeFilters  = {@ComponentScan.Filter(
        // 排除不需要的@Component,@Configuration
        type = FilterType.ASSIGNABLE_TYPE, classes = {JwtAuthenticationTokenFilter.class, FilterConfig.class, TokenService.class})})

2、排除包

@ComponentScan(basePackages = {"cn.hg", "cn.hutool"},excludeFilters  = {@ComponentScan.Filter(
        // 排除不需要扫描的包
        type = FilterType.REGEX, pattern = {
                "cn.hg.demo.*"
        })})

Logo

魔乐社区(Modelers.cn) 是一个中立、公益的人工智能社区,提供人工智能工具、模型、数据的托管、展示与应用协同服务,为人工智能开发及爱好者搭建开放的学习交流平台。社区通过理事会方式运作,由全产业链共同建设、共同运营、共同享有,推动国产AI生态繁荣发展。

更多推荐