How to reproduce the behavior of a welding instance in Spring

I use

@Inject 
Instance<Interface> xxx 

which will implement a new instance of each class that implements the interface. This is very useful because I do not need to know how many or who these classes are to create them, and I can repeat them without knowing how many of them.

Now I do not know how to reproduce this behavior using Spring.

Can you help me?

Thanks,

+4
source share
3 answers

The best solution I have found so far is to enter applicationContext and

@Inject
ApplicationContext applicationContext;

...

Map<String, Object> mapInstance = applicationContext.getBeansWithAnnotation(MyAnnotation.class);
+1
source

Spring @Inject , @Autowired. , @Component, @Repository, @Service @Controller, Beans.xml.

: http://docs.spring.io/spring/docs/4.0.1.RELEASE/spring-framework-reference/htmlsingle/#beans-factory-collaborators

0

@Autowired
private List<Interface> interfaces;

CDI bean List<Interface>, Spring beans Interface.

,

@Autowired
private Map<String, Interface> interfaces;

beans Interface bean.

( javax.inject.Inject , @Autowired @Inject.)

0

Source: https://habr.com/ru/post/1525048/


All Articles