V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
liian2019
V2EX  ›  Java

兄弟们,帮忙看一个 spring 的问题

  •  
  •   liian2019 · 2021-06-29 17:26:11 +08:00 · 854 次点击
    这是一个创建于 1022 天前的主题,其中的信息可能已经有所发展或是发生改变。
    我有一个壳子项目,里面集成了 4 个 jar 包,但是这四个 jar 包有些 bean 是冲突的,所以使用 @ComponentScan 的 filter 来排除掉一些类。启动类注解如下:
    @SpringBootApplication(exclude = {SecurityAutoConfiguration.class})
    @EnableScheduling
    @EnableAsync
    @EnableAspectJAutoProxy(exposeProxy = true)
    @EnableTransactionManagement
    @ComponentScan(basePackages = {"com.liian"},excludeFilters =
    {@ComponentScan.Filter(type = FilterType.ASSIGNABLE_TYPE,classes = {ParamValidateConfiguration.class,
    MybatisPlusConfig.class,MPMetaObjectHandler.class})})


    现在问题是 ParamValidateConfiguration 和 MybatisPlusConfig 可以被排除掉,而 MPMetaObjectHandler 不可以。经过观察发现,前两个标注了 @Configuration 注解,而后一个标注的是 @Component 注解,实验后面发现只要标注的是 @Component 注解的类都不能被排除掉。

    请问下大佬们知道是为什么嘛
    第 1 条附言  ·  2021-06-30 14:19:56 +08:00
    找到问题了,@ComponentScan 注解里了的 filter 没问题。原因是 jar 包里面有其它类标注了 @ComponentScan,导致有的 class 被重复加载多次导致的。
    目前尚无回复
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3596 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 26ms · UTC 11:10 · PVG 19:10 · LAX 04:10 · JFK 07:10
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.