I am trying to understand the javax.inject
package and I am not clear what the javax.inject.Named
annotation is supposed to be used for. The Javadoc does not explain the the idea behind it.
Javadoc is at http://download.oracle.com/javaee/6/api/javax/inject/Named.html
I am using Spring 3.0 to write some sample programs, by putting @Named
on a bean it seems to add it to the bean factory but the Javadoc description is so light I can't tell if that is the standard behavior or Spring specific behavior.
My questions are:
@Named
and @Qualifier
@Component
in Spring?Update 1 there is an excellent explanation of @Named
and @Qualifier
at Nice article about @Named
and @Qualifier
https://dzone.com/articles/java-ee6-cdi-named-components thanks @xmedeko for linking to it the comment below.
Use @Named
to differentiate between different objects of the same type bound in the same scope.
@Named("maxWaitTime")
public long maxWaitTimeMs;
@Named("minWaitTime")
public long minWaitTimeMs;
Without the @Named
qualifier, the injector would not know which long to bind to which variable.
If you want to create annotations that act like @Named
, use the @Qualifier
annotation when creating them.
If you look at @Named
, it is itself annotated with @Qualifier
.