Frage

I'm trying more and more to design and build my applications such that they are framework agnostic. This means using JSR annotations instead of Spring annotations, JPA2 interfaces, etc. but I find myself having a lot of difficulty at times.

For example, at the moment, I need to retrieve a list of all beans of a particular class. Using a Spring-specific method, I can use the ApplicationContext to .getBeansOfType(Clazz), but I'm trying to do this without using the Spring ApplicationContext.

Is there a JSR equivalent to Spring's application context?

Ex (quick psuedo code):

@Autowired private ApplicationContext ctx;

protected Map<String, Clazz> getBeans(){
   return ctx.getBeansOfType( Clazz );
}

How can I do this without using Spring?

War es hilfreich?

Lösung

I think that not.

For Spring, you could use:

 @Inject
 private Map<String, Foo> fooBeans;

to avoid explicit reference to ApplicationContex, but AFAIK this will not work with others DI containers.

Andere Tipps

You won't find a framework agnostic way of doing this. For CDI you'd use

@Inject Instance<Foo> fooBeans;

Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top