|
1 | 1 | <?xml version="1.0" encoding="UTF-8"?>
|
2 |
| -<section xmlns="http://docbook.org/ns/docbook" version="5.0" |
3 |
| - xmlns:xlink="http://www.w3.org/1999/xlink" |
| 2 | +<section xml:id="beans-annotation-config" |
| 3 | + xmlns="http://docbook.org/ns/docbook" version="5.0" |
| 4 | + xmlns:xl="http://www.w3.org/1999/xlink" |
4 | 5 | xmlns:xi="http://www.w3.org/2001/XInclude"
|
5 |
| - xml:id="beans-annotation-config"> |
| 6 | + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" |
| 7 | + xsi:schemaLocation=" |
| 8 | + http://docbook.org/ns/docbook http://www.docbook.org/xml/5.0/xsd/docbook.xsd |
| 9 | + http://www.w3.org/1999/xlink http://www.docbook.org/xml/5.0/xsd/xlink.xsd"> |
6 | 10 | <title>Annotation-based container configuration</title>
|
7 | 11 |
|
8 | 12 | <sidebar>
|
|
25 | 29 | linkend="beans-java">JavaConfig</link> option, Spring allows annotations
|
26 | 30 | to be used in a non-invasive way, without touching the target components
|
27 | 31 | source code and that in terms of tooling, all configuration styles are
|
28 |
| - supported by the <ulink url="http://www.springsource.com/products/sts" |
29 |
| - >SpringSource Tool Suite</ulink>.</para> |
| 32 | + supported by the <link xl:href="http://www.springsource.com/products/sts" |
| 33 | + >SpringSource Tool Suite</link>.</para> |
30 | 34 | </sidebar>
|
31 | 35 |
|
32 | 36 | <para>An alternative to XML setups is provided by annotation-based
|
|
51 | 55 | JSR-330 (Dependency Injection for Java) annotations contained in the
|
52 | 56 | javax.inject package such as <classname>@Inject</classname> and
|
53 | 57 | <literal> @Named</literal>. Details about those annotations can be found in the <link linkend="beans-standard-annotations"
|
54 |
| - >relevant section</link>. <note> Annotation injection is performed |
| 58 | + >relevant section</link>. <note><para>Annotation injection is performed |
55 | 59 | <emphasis>before</emphasis> XML injection, thus the latter configuration
|
56 | 60 | will override the former for properties wired through both approaches.
|
57 |
| - </note> As always, you can register them as individual bean definitions, but |
| 61 | + </para></note> As always, you can register them as individual bean definitions, but |
58 | 62 | they can also be implicitly registered by including the following tag in an
|
59 | 63 | XML-based Spring configuration (notice the inclusion of the
|
60 | 64 | <literal>context</literal> namespace):</para>
|
|
72 | 76 |
|
73 | 77 | </beans></programlisting>
|
74 | 78 |
|
75 |
| - <para>(The implicitly registered post-processors include <ulink |
76 |
| - url="http://static.springframework.org/spring/docs/current/api/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.html" |
77 |
| - ><classname>AutowiredAnnotationBeanPostProcessor</classname></ulink>, <ulink |
78 |
| - url="http://static.springframework.org/spring/docs/current/api/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.html" |
79 |
| - ><classname>CommonAnnotationBeanPostProcessor</classname></ulink>, <ulink |
80 |
| - url="http://static.springframework.org/spring/docs/current/api/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.html" |
81 |
| - ><classname>PersistenceAnnotationBeanPostProcessor</classname></ulink>, as |
82 |
| - well as the aforementioned <ulink |
83 |
| - url="http://static.springframework.org/spring/docs/current/api/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.html" |
84 |
| - ><classname>RequiredAnnotationBeanPostProcessor</classname></ulink>.)</para> |
| 79 | + <para>(The implicitly registered post-processors include <link |
| 80 | + xl:href="http://static.springframework.org/spring/docs/current/api/org/springframework/beans/factory/annotation/AutowiredAnnotationBeanPostProcessor.html" |
| 81 | + ><classname>AutowiredAnnotationBeanPostProcessor</classname></link>, <link |
| 82 | + xl:href="http://static.springframework.org/spring/docs/current/api/org/springframework/context/annotation/CommonAnnotationBeanPostProcessor.html" |
| 83 | + ><classname>CommonAnnotationBeanPostProcessor</classname></link>, <link |
| 84 | + xl:href="http://static.springframework.org/spring/docs/current/api/org/springframework/orm/jpa/support/PersistenceAnnotationBeanPostProcessor.html" |
| 85 | + ><classname>PersistenceAnnotationBeanPostProcessor</classname></link>, as |
| 86 | + well as the aforementioned <link |
| 87 | + xl:href="http://static.springframework.org/spring/docs/current/api/org/springframework/beans/factory/annotation/RequiredAnnotationBeanPostProcessor.html" |
| 88 | + ><classname>RequiredAnnotationBeanPostProcessor</classname></link>.)</para> |
85 | 89 |
|
86 | 90 | <note>
|
87 | 91 | <para><literal><context:annotation-config/></literal> only looks for
|
|
95 | 99 | information.</para>
|
96 | 100 | </note>
|
97 | 101 |
|
98 |
| - <section id="beans-required-annotation"> |
| 102 | + <section xml:id="beans-required-annotation"> |
99 | 103 | <title><interfacename>@Required</interfacename></title>
|
100 | 104 |
|
101 | 105 | <para>The <interfacename>@Required</interfacename> annotation applies to
|
|
124 | 128 | and values even when you use the class outside of a container.</para>
|
125 | 129 | </section>
|
126 | 130 |
|
127 |
| - <section id="beans-autowired-annotation"> |
| 131 | + <section xml:id="beans-autowired-annotation"> |
128 | 132 | <title><interfacename>@Autowired</interfacename></title>
|
129 | 133 |
|
130 | 134 | <para>As expected, you can apply the
|
131 | 135 | <interfacename>@Autowired</interfacename> annotation to "traditional"
|
132 | 136 | setter methods:</para>
|
133 | 137 |
|
134 |
| - |
| 138 | + |
135 | 139 |
|
136 | 140 | <programlisting language="java">public class SimpleMovieLister {
|
137 | 141 |
|
|
145 | 149 | <lineannotation>// ...</lineannotation>
|
146 | 150 | }</programlisting>
|
147 | 151 |
|
148 |
| - <note> |
| 152 | + <note> |
149 | 153 | <para>JSR 330's @Inject annotation can be used in place of Spring's
|
150 | 154 | <interfacename>@Autowired</interfacename> annotation in the examples below. See <link linkend="beans-standard-annotations"
|
151 | 155 | >here</link> for more details</para>
|
152 | 156 | </note>
|
153 |
| - |
154 |
| - |
| 157 | + |
| 158 | + |
155 | 159 | <para>You can also apply the annotation to methods with arbitrary names
|
156 | 160 | and/or multiple arguments:</para>
|
157 | 161 |
|
|
310 | 314 | </note>
|
311 | 315 | </section>
|
312 | 316 |
|
313 |
| - <section id="beans-autowired-annotation-qualifiers"> |
| 317 | + <section xml:id="beans-autowired-annotation-qualifiers"> |
314 | 318 | <title>Fine-tuning annotation-based autowiring with qualifiers</title>
|
315 | 319 |
|
316 | 320 | <para>Because autowiring by type may lead to multiple candidates, it is
|
@@ -635,12 +639,12 @@ public @interface MovieQualifier {
|
635 | 639 | </beans></programlisting>
|
636 | 640 | </section>
|
637 | 641 |
|
638 |
| - <section id="beans-custom-autowire-configurer"> |
| 642 | + <section xml:id="beans-custom-autowire-configurer"> |
639 | 643 | <title><classname>CustomAutowireConfigurer</classname></title>
|
640 | 644 |
|
641 |
| - <para>The <ulink |
642 |
| - url="http://static.springframework.org/spring/docs/current/api/org/springframework/beans/factory/annotation/CustomAutowireConfigurer.html" |
643 |
| - ><classname>CustomAutowireConfigurer</classname></ulink> is a |
| 645 | + <para>The <link |
| 646 | + xl:href="http://static.springframework.org/spring/docs/current/api/org/springframework/beans/factory/annotation/CustomAutowireConfigurer.html" |
| 647 | + ><classname>CustomAutowireConfigurer</classname></link> is a |
644 | 648 | <interfacename>BeanFactoryPostProcessor</interfacename> that enables you
|
645 | 649 | to register your own custom qualifier annotation types even if they are
|
646 | 650 | not annotated with Spring's <interfacename>@Qualifier</interfacename>
|
@@ -675,7 +679,7 @@ public @interface MovieQualifier {
|
675 | 679 | will be selected.</para>
|
676 | 680 | </section>
|
677 | 681 |
|
678 |
| - <section id="beans-resource-annotation"> |
| 682 | + <section xml:id="beans-resource-annotation"> |
679 | 683 | <title><interfacename>@Resource</interfacename></title>
|
680 | 684 |
|
681 | 685 | <para>Spring also supports injection using the JSR-250
|
@@ -719,9 +723,9 @@ public @interface MovieQualifier {
|
719 | 723 | <para>The name provided with the annotation is resolved as a bean name by
|
720 | 724 | the <interfacename>ApplicationContext</interfacename> of which the
|
721 | 725 | <classname>CommonAnnotationBeanPostProcessor</classname> is aware. The
|
722 |
| - names can be resolved through JNDI if you configure Spring's <ulink |
723 |
| - url="http://static.springframework.org/spring/docs/current/api/org/springframework/jndi/support/SimpleJndiBeanFactory.html" |
724 |
| - ><classname>SimpleJndiBeanFactory</classname></ulink> explicitly. |
| 726 | + names can be resolved through JNDI if you configure Spring's <link |
| 727 | + xl:href="http://static.springframework.org/spring/docs/current/api/org/springframework/jndi/support/SimpleJndiBeanFactory.html" |
| 728 | + ><classname>SimpleJndiBeanFactory</classname></link> explicitly. |
725 | 729 | However, it is recommended that you rely on the default behavior and
|
726 | 730 | simply use Spring's JNDI lookup capabilities to preserve the level of
|
727 | 731 | indirection.</para>
|
@@ -760,7 +764,7 @@ public @interface MovieQualifier {
|
760 | 764 | }</programlisting>
|
761 | 765 | </section>
|
762 | 766 |
|
763 |
| - <section id="beans-postconstruct-and-predestroy-annotations"> |
| 767 | + <section xml:id="beans-postconstruct-and-predestroy-annotations"> |
764 | 768 | <title><interfacename>@PostConstruct</interfacename> and
|
765 | 769 | <interfacename>@PreDestroy</interfacename></title>
|
766 | 770 |
|
|
0 commit comments