Can't get @Component to be inherited in Spring?

后端 未结 2 1575
谎友^
谎友^ 2021-02-04 09:51

In my project there\'s a common base class that all client classes extend. This has an @Autowired field that needs to be injected by Hibernate. These are all grouped together in

2条回答
  •  傲寒
    傲寒 (楼主)
    2021-02-04 10:34

    I've dealt with this issue by creating my own annotation (heritable) and then customizing classpath scanning:

    @Target(ElementType.TYPE)
    @Retention(RetentionPolicy.RUNTIME)
    @Component 
    @Inherited
    public @interface BusinessService {
    }
    

    Spring configuration look likes this:

    
            
        
    

    from Spring doc 5.10.3 Using filters to customize scanning

提交回复
热议问题