<para>Starting from Spring 3.0, Spring offers support for JSR-330 standard annotations (Dependency Injection).
<para>Starting with Spring 3.0, Spring offers support for JSR-330 standard annotations (Dependency Injection).
Those annotations are scanned in the same way as the Spring annotations. You just need to have the relevant jars in your classpath.
Those annotations are scanned in the same way as the Spring annotations. You just need to have the relevant jars in your classpath.
</para>
</para>
<note>
<note>
If you are using Maven, the <interfacename>javax.inject</interfacename> artifact is available on the standard Maven repository (<ulinkurl="http://repo1.maven.org/maven2/javax/inject/javax.inject/1/">http://repo1.maven.org/maven2/javax/inject/javax.inject/1/</ulink>). You can add the following dependency to your file pom.xml:
<para>
<programlistinglanguage="xml">
If you are using Maven, the <interfacename>javax.inject</interfacename> artifact is available
As for <interfacename>@Autowired</interfacename>, it is possible to use <interfacename>@Inject</interfacename> at the class-level, field-level, method-level and constructor-argument level.
<para>As with <interfacename>@Autowired</interfacename>, it is possible to use <interfacename>@Inject</interfacename>
at the class-level, field-level, method-level and constructor-argument level.
If you would like to use a qualified name for the dependency that should be injected, you should use the <interfacename>@Named</interfacename> annotation as follows:
If you would like to use a qualified name for the dependency that should be injected,
<programlistinglanguage="java">
you should use the <interfacename>@Named</interfacename> annotation as follows:
It is very common to use <interfacename>@Component</interfacename> without specifying a name for the component. <interfacename>@Named</interfacename> can be used in a similar fashion:
It is very common to use <interfacename>@Component</interfacename> without
<programlistinglanguage="java">
specifying a name for the component. <interfacename>@Named</interfacename>
<title>Limitations of the standard approach</title>
<title>Limitations of the standard approach</title>
<para>When working with standard annotations, it is important to know that some significant features are not available as shown in the table below:</para>
<para>When working with standard annotations, it is important to know that
some significant features are not available as shown in the table below:</para>
<para><tableid="annotations-comparison">
<para><tableid="annotations-comparison">
<title>Spring annotations vs standard annotations</title>
<title>Spring annotations vs. standard annotations</title>
@ -133,58 +143,51 @@ When using <interfacename>@Named</interfacename>, it is possible to use componen
<tbody>
<tbody>
<row>
<row>
<entry>@Autowired</entry>
<entry>@Autowired</entry>
<entry>@Inject</entry>
<entry>@Inject</entry>
<entry>@Inject has no 'required' attribute</entry>
<entry>@Inject has no 'required' attribute</entry>
</row>
</row>
<row>
<row>
<entry>@Component</entry>
<entry>@Component</entry>
<entry>@Named</entry>
<entry>@Named</entry>
<entry>—</entry>
<entry></entry>
</row>
</row>
<row>
<row>
<entry>@Scope("singleton")</entry>
<entry>@Scope("singleton")</entry>
<entry>@Singleton</entry>
<entry>@Singleton</entry>
<entry>
<entry>
<para>
<para>
jsr-330 default scope is like Spring's <interfacename>prototype</interfacename>. However, in order to keep it consistent with Spring's general defaults, a jsr-330 bean declared in the Spring container is a <interfacename>singleton</interfacename> by default. In order to use another scope than <interfacename>singleton</interfacename>, you should use Spring's <interfacename>@Scope</interfacename> annotation.
The JSR-330 default scope is like Spring's <interfacename>prototype</interfacename>.
However, in order to keep it consistent with Spring's general defaults,
a JSR-330 bean declared in the Spring container is a
<interfacename>singleton</interfacename> by default. In order to use a
scope other than <interfacename>singleton</interfacename>, you should use Spring's
<interfacename>@Scope</interfacename> annotation.
</para>
</para>
<para>
<para>
<interfacename>javax.inject</interfacename> also provides a <ulinkurl="http://download.oracle.com/javaee/6/api/javax/inject/Scope.html">@Scope</ulink> annotation. Nevertheless, this one only aims to be used for creating your own annotations.
<interfacename>javax.inject</interfacename> also provides a