V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
liian2019
V2EX  ›  Java

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

  •  
  •   liian2019 · Jun 29, 2021 · 1682 views
    This topic created in 1776 days ago, the information mentioned may be changed or developed.
    我有一个壳子项目,里面集成了 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 注解的类都不能被排除掉。

    请问下大佬们知道是为什么嘛
    Supplement 1  ·  Jun 30, 2021
    找到问题了,@ComponentScan 注解里了的 filter 没问题。原因是 jar 包里面有其它类标注了 @ComponentScan,导致有的 class 被重复加载多次导致的。
    No Comments Yet
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   875 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 29ms · UTC 21:38 · PVG 05:38 · LAX 14:38 · JFK 17:38
    ♥ Do have faith in what you're doing.