How to get list of Interfaces from @ComponentScan packages

后端 未结 3 945
慢半拍i
慢半拍i 2020-12-31 19:12

I would like to implement something similar to Spring Data.

Developer can define some interfaces, add a custom annotation to the interfaces to mark them, (my code w

3条回答
  •  隐瞒了意图╮
    2020-12-31 19:40

    We do this all the time without incident.

    Below is the code for the service bean that will be using the List.

    @Service
    public class SomeService {
    
    @Autowired
    List myInterfaceInstances;
    
    //class stuff
    
    }
    

    Next we have the implementations of the interface.

    @Component
    public class SomeImpl implements MyInterface {
    
    //class stuff
    
    }
    

    and another one just for good measure...

    @Component
    public class SomeOtherImpl implements MyInterface {
    
    //class stuff
    
    }
    

提交回复
热议问题