* eliminated all usage of "the section entitled", because <xref> links already render including "the section called ". This was resulting in sentences like 'see also the section entitled the section called "@Autowired"'. This issue affected nearly all sections of the documentation, so went beyond just beans.xml
* fixed table overflow in the "Using filters to customize scanning" section (approx. p.90)
* fixed all code overflows in <programlisting/> elements
* corrected a couple minor syntax errors with SpEL examples (missing closing braces)
* added 'language="..."' element to <programlisting> elements where appropriate to enable syntax highlighting.
* normalized all code indention to four-space (some code listings were using one- and two-space)
* updated all code listings to use same-line opening braces.
* eliminated section regarding backward compatibility with Spring DTDs and singleton=true|false. This seems like cruft to me, and we shouldn't keep historical notes around forever.
* Added <note> regarding the new thread scope (SimpleThreadScope) to Section 3.5 Bean Scopes. Also updated the section on registering a custom Scope implementation to use the SimpleThreadScope as an example.
* updated the new-in-3.xml section to improve the @Configuration example
<para>This chapter covers the Spring Framework implementation of the
Inversion of Control (IoC) <footnote>
<para>See the section entitled <xref
linkend="background-ioc" /></para>
<para>See <xreflinkend="background-ioc"/></para>
</footnote>principle. IoC is also known as <emphasis>dependency
injection</emphasis> (DI). It is a process whereby objects define their
dependencies, that is, the other objects they work with, only through
@ -216,8 +215,8 @@ The footnote should x-ref to first section in that chapter but I can't find the
@@ -216,8 +215,8 @@ The footnote should x-ref to first section in that chapter but I can't find the
metadata from a variety of external resources such as the local file
system, from the Java <literal>CLASSPATH</literal>, and so on.</para>
<programlistinglanguage="java">ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"services.xml",
new ClassPathXmlApplicationContext(new String[] {"services.xml", "daos.xml"});</programlisting>
<note>
<para>After you learn about Spring's IoC container, you may want to
@ -233,7 +232,7 @@ The footnote should x-ref to first section in that chapter but I can't find the
@@ -233,7 +232,7 @@ The footnote should x-ref to first section in that chapter but I can't find the
<para>The following example shows the service layer objects
@ -256,13 +255,14 @@ The footnote should x-ref to first section in that chapter but I can't find the
@@ -256,13 +255,14 @@ The footnote should x-ref to first section in that chapter but I can't find the
<para>The following example shows the data access objects
<!-- additional collaborators and configuration for this bean go here -->
</bean>
@ -361,7 +361,8 @@ The footnote should x-ref to first section in that chapter but I can't find the
@@ -361,7 +361,8 @@ The footnote should x-ref to first section in that chapter but I can't find the
to read bean definitions and access them as follows:</para>
<programlistinglanguage="java">// create and configure beans
ApplicationContext context = new ClassPathXmlApplicationContext(new String[] {"services.xml", "daos.xml"});
ApplicationContext context =
new ClassPathXmlApplicationContext(new String[] {"services.xml", "daos.xml"});
// retrieve configured instance
PetStoreServiceImpl service = context.getBean("petStore", PetStoreServiceImpl.class);
@ -1076,7 +1077,7 @@ public class ExampleBean {
@@ -1076,7 +1077,7 @@ public class ExampleBean {
properties themselves are not set until the bean <emphasis>is actually
created</emphasis>. Beans that are singleton-scoped and set to be
pre-instantiated (the default) are created when the container is
created. Scopes are defined in the section <xref
created. Scopes are defined in <xref
linkend="beans-factory-scopes" /> Otherwise, the bean is created only
when it is requested. Creation of a bean potentially causes a graph of
beans to be created, as the bean's dependencies and its dependencies'
@ -1300,19 +1301,19 @@ public class ExampleBean {
@@ -1300,19 +1301,19 @@ public class ExampleBean {
linkend="beans-p-namespace">p-namespace</link> for even more succinct
<lineannotation><!-- a bean with an id of '<literal>theTargetBean</literal>' must exist; otherwise an XML exception will be thrown --></lineannotation>
<lineannotation><!-- a bean with id '<literal>theTargetBean</literal>' must exist; otherwise an exception will be thrown --></lineannotation>
<idref local="theTargetBean"/>
</property></programlisting>
@ -1465,14 +1467,12 @@ public class ExampleBean {
@@ -1465,14 +1467,12 @@ public class ExampleBean {
</bean></programlisting>
<programlistinglanguage="xml"><lineannotation><!-- in the child (descendant) context --></lineannotation>
<bean id="accountService" <lineannotation><-- notice that the name of this bean is the <emphasis
role="bold">same</emphasis> as the name of the <literal>parent</literal> bean</lineannotation>
<bean id="accountService" <lineannotation><-- bean name is the same as the parent bean --></lineannotation>
<para>If you use Java 5 and thus have access to source-level
annotations, you may find <xref
linkend="metadata-annotations-required" /> to be of interest.</para>
annotations, you may find <literal><xref
linkend="metadata-annotations-required" /></literal> to be of interest.</para>
</section>
<sectionid="beans-factory-method-injection">
@ -2278,12 +2278,13 @@ public class CommandManager implements ApplicationContextAware {
@@ -2278,12 +2278,13 @@ public class CommandManager implements ApplicationContextAware {
return command.execute();
}
<lineannotation>// the <interfacename>Command</interfacename> returned here could be an implementation that executes asynchronously, or whatever</lineannotation>
protected Command createCommand() {
return this.applicationContext.getBean("command", Command.class); <lineannotation>// notice the Spring API dependency</lineannotation>
<lineannotation>// notice the Spring API dependency!</lineannotation>
public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
public void setApplicationContext(ApplicationContext applicationContext)
throws BeansException {
this.applicationContext = applicationContext;
}
}</programlisting>
@ -2565,6 +2566,14 @@ public class ReplacementComputeValue implements MethodReplacer {
@@ -2565,6 +2566,14 @@ public class ReplacementComputeValue implements MethodReplacer {
</tbody>
</tgroup>
</table>
<note>
<title>Thread-scoped beans</title>
<para>As of Spring 3.0, a <emphasis>thread scope</emphasis> is available, but is
not registered by default. For more information, see the documentation for
@ -2609,11 +2618,8 @@ public class ReplacementComputeValue implements MethodReplacer {
@@ -2609,11 +2618,8 @@ public class ReplacementComputeValue implements MethodReplacer {
<lineannotation><!-- the following is equivalent, though redundant (singleton scope is the default); using <literal>spring-beans-2.0.dtd</literal> --></lineannotation>
<lineannotation><!-- the following is equivalent and preserved for backward compatibility in <literal>spring-beans.dtd</literal> --></lineannotation>
@ -2648,10 +2654,7 @@ public class ReplacementComputeValue implements MethodReplacer {
@@ -2648,10 +2654,7 @@ public class ReplacementComputeValue implements MethodReplacer {
<para>The following example defines a bean as a prototype in XML:</para>
<programlistinglanguage="xml"><lineannotation><!-- using <literal>spring-beans-2.0.dtd</literal> --></lineannotation>
<lineannotation><!-- the following is equivalent and preserved for backward compatibility in <literal>spring-beans.dtd</literal> --></lineannotation>
<para>In contrast to the other scopes, Spring does not manage the
complete lifecycle of a prototype bean: the container instantiates,
@ -2694,32 +2697,6 @@ public class ReplacementComputeValue implements MethodReplacer {
@@ -2694,32 +2697,6 @@ public class ReplacementComputeValue implements MethodReplacer {
and injecting its dependencies. If you need a new instance of a
prototype bean at runtime more than once, see <xref
<filename>spring-beans-2.0.dtd</filename> DTD or the Spring 2.0 XSD
schema, you must use the <literal>scope</literal> attribute, because
the <literal>singleton</literal> attribute was removed from the
definition of the new DTD and XSD files in favor of the
<literal>scope</literal> attribute.</para>
<para>This means that if you use the <literal>singleton</literal>
attribute in an XML bean definition, you <emphasis>must</emphasis>
reference the <filename>spring-beans.dtd</filename> DTD <emphasis>in
that file</emphasis>. If you use the <literal>scope</literal>
attribute, you <emphasis>must</emphasis> reference either the
<filename>spring-beans-2.0.dtd</filename> DTD or the
<filename>spring-beans-3.0.xsd</filename> XSD <emphasis>in that
file</emphasis>.</para>
</note>
</section>
<sectionid="beans-factory-scopes-other">
@ -2766,7 +2743,9 @@ public class ReplacementComputeValue implements MethodReplacer {
@@ -2766,7 +2743,9 @@ public class ReplacementComputeValue implements MethodReplacer {
@ -3131,18 +3110,21 @@ public class ReplacementComputeValue implements MethodReplacer {
@@ -3131,18 +3110,21 @@ public class ReplacementComputeValue implements MethodReplacer {
<para>Suppose that you write your custom
<interfacename>Scope</interfacename> implementation, and then register
it as follows:</para>
it as below.</para>
<note>
<para>The example below uses <literal>SimpleThreadScope</literal>
which is included with Spring, but not registered by default. The instructions
would be the same for your own custom <literal>Scope</literal> implementations.</para>
</note>
<programlistinglanguage="java"><lineannotation>// note: the <classname>ThreadScope</classname> class does <emphasis
role="bold">not</emphasis> ship with the Spring Framework</lineannotation>
@ -5140,10 +5125,11 @@ public class JpaMovieFinder implements MovieFinder {
@@ -5140,10 +5125,11 @@ public class JpaMovieFinder implements MovieFinder {
@ -5154,11 +5140,12 @@ public class JpaMovieFinder implements MovieFinder {
@@ -5154,11 +5140,12 @@ public class JpaMovieFinder implements MovieFinder {
<interfacename>@Repository</interfacename> annotations and using "stub"
@ -5184,22 +5171,21 @@ public class JpaMovieFinder implements MovieFinder {
@@ -5184,22 +5171,21 @@ public class JpaMovieFinder implements MovieFinder {
<literal>@Configuration</literal> annotated classes. Here is a simple
example:</para>
<programlisting>@Component
<programlistinglanguage="java">@Component
public class FactoryMethodComponent {
@Bean @Qualifier("public")
public TestBean publicInstance() {
return new TestBean("publicInstance");
}
@Bean @Qualifier("public")
public TestBean publicInstance() {
return new TestBean("publicInstance");
}
public void DoWork()
{
// Component method implementation omitted
}
public void doWork() {
// Component method implementation omitted
}
}</programlisting>
<para>This class is a Spring component that has application-specific
code contained in its <methodname>DoWork</methodname> method. However,
code contained in its <methodname>doWork</methodname> method. However,
it also contributes a bean definition that has a factory method
referring to the method <methodname>publicInstance</methodname>. The
<literal>@Bean</literal> annotation identifies the factory method and
@ -5208,37 +5194,39 @@ public class FactoryMethodComponent {
@@ -5208,37 +5194,39 @@ public class FactoryMethodComponent {
annotations that can be specified are <literal>@Scope</literal>,
<literal>@Lazy</literal>, and custom qualifier annotations. Autowired
fields and methods are supported as previously discussed, with
additional support for autowiring of @Bean methods:</para>
additional support for autowiring of <literal>@Bean</literal> methods:</para>
<programlistinglanguage="java">@Component
public class FactoryMethodComponent {
private static int i;
private static int i;
@Bean @Qualifier("public")
public TestBean publicInstance() {
return new TestBean("publicInstance");
}
@Bean @Qualifier("public")
public TestBean publicInstance() {
return new TestBean("publicInstance");
}
// use of a custom qualifier and autowiring of method parameters
// use of a custom qualifier and autowiring of method parameters
<para>This chapter is not an introduction to JMX... it doesn't try to
explain the motivations of why one might want to use JMX (or indeed what
the letters JMX actually stand for). If you are new to JMX, check out
the section entitled <xreflinkend="jmx-resources"/> at the end of this
chapter.</para>
<xreflinkend="jmx-resources"/> at the end of this chapter.</para>
</sidebar>
<para>Specifically, Spring's JMX support provides four core
@ -128,7 +127,7 @@ public class JmxTestBean implements IJmxTestBean {
@@ -128,7 +127,7 @@ public class JmxTestBean implements IJmxTestBean {
<literal>beans</literal><interfacename>Map</interfacename> is used as the
<classname>ObjectName</classname> for the bean referenced by the
corresponding entry value. This behavior can be changed as described in
the section entitled <xreflinkend="jmx-naming"/>.</para>
<xreflinkend="jmx-naming"/>.</para>
<para>With this configuration the <literal>testBean</literal> bean is
exposed as an MBean under the <classname>ObjectName</classname>
@ -270,8 +269,7 @@ public class JmxTestBean implements IJmxTestBean {
@@ -270,8 +269,7 @@ public class JmxTestBean implements IJmxTestBean {
already a valid JMX MBean and will be automatically registered by
Spring. By default, beans that are autodetected for JMX registration
have their bean name used as the <classname>ObjectName</classname>. This
behavior can be overridden as detailed in the section entitled
<xreflinkend="jmx-naming"/>.</para>
behavior can be overridden as detailed in <xreflinkend="jmx-naming"/>.</para>
</section>
<sectionid="jmx-exporting-registration-behavior">
@ -954,8 +952,8 @@ public class AnnotationTestBean implements IJmxTestBean {
@@ -954,8 +952,8 @@ public class AnnotationTestBean implements IJmxTestBean {
to include it. The only problem with this approach is that the name of
the <classname>JmxTestBean</classname> now has business meaning. You can
address this issue by changing the default behavior for
<classname>ObjectName</classname> creation as defined in the section
entitled <xreflinkend="jmx-naming"/>.</para>
<classname>ObjectName</classname> creation as defined in
<xreflinkend="jmx-naming"/>.</para>
</section>
<sectionid="jmx-interface-java">
@ -1760,4 +1758,4 @@ public class JmxTestBean implements IJmxTestBean, NotificationPublisherAware {
@@ -1760,4 +1758,4 @@ public class JmxTestBean implements IJmxTestBean, NotificationPublisherAware {
normal and global). This is not a specific feature of Spring Portlet MVC
itself, but rather of the <interfacename>WebApplicationContext</interfacename>
container(s) that Spring Portlet MVC uses. These bean scopes are described
in detail in the section entitled <xreflinkend="beans-factory-scopes-other"/></para>
in detail in <xreflinkend="beans-factory-scopes-other"/></para>
</section>
<note>
@ -921,8 +921,8 @@ public class SampleController extends AbstractController {
@@ -921,8 +921,8 @@ public class SampleController extends AbstractController {
the view technologies from Spring Web MVC. This includes not only the
various <interfacename>View</interfacename> implementations themselves,
but also the <interfacename>ViewResolver</interfacename> implementations.
For more information, refer to the sections entitled
<xreflinkend="view"/> and <xreflinkend="mvc-viewresolver"/> respectively.</para>
For more information, refer to <xreflinkend="view"/> and