views:

190

answers:

3

I have played with the JSR-299 Reference Implementation "Weld" with the purpose of using it in a stand-alone application, and I have had a look at the documentation, and marveled at the magic.

My question is how the producer of a given object to be @Inject'ed is found?

Either the java compiler produces hints for annotations which is easily found by the classloader, or the complete classpath must be traversed loading all classes to see what they do which sounds highly inefficient to me, or it is a completely different approach.

What is the trick?

A: 

I assume that it works the same as in Seam: in which the classpath is indeed scanned. The impl will also search for the @produce with the smallest matching scope, so you can have for instance one produce on session level for logged in users and another on application level for anonymous users.

disown
A: 

Dunno, but this @Inject partially done by Hibernate's father was finally reworked/influenced at the end by SpringSource and Google. Perhaps it works a bit like Guice?

Sebastien Lorber
the `@Inject` annotation itself was specified by a team formed by Guice and Spring members. It is a part of another JSR.
Bozho
+2  A: 

The classpath is scanned for "bean archives". Bean archives are those libraries that contain META-INF/beans.xml. All beans in these archives are automatically registered with the BeanManager and their annotations are parsed and stored. Whenever a producer is needed the bean manager is consulted about eligible producers

Bozho