[SPR-5824] Removed references to StandardScopes from the reference manual; updated examples accordingly; corrected typos; etc.

This commit is contained in:
Sam Brannen 2009-06-12 14:29:29 +00:00
parent 3caecbd1ef
commit 7038e1fa3d
1 changed files with 30 additions and 32 deletions

View File

@ -2626,10 +2626,10 @@ public class ReplacementComputeValue implements MethodReplacer {
<row> <row>
<entry><para> <link <entry><para> <link
linkend="beans-factory-scopes-global-session">session</link> linkend="beans-factory-scopes-session">session</link>
</para></entry> </para></entry>
<entry><para>Scopes a single bean definition to the lifecycle of a <entry><para>Scopes a single bean definition to the lifecycle of an
HTTP <interfacename>Session</interfacename>. Only valid in the HTTP <interfacename>Session</interfacename>. Only valid in the
context of a web-aware Spring context of a web-aware Spring
<interfacename>ApplicationContext</interfacename>.</para></entry> <interfacename>ApplicationContext</interfacename>.</para></entry>
@ -2991,18 +2991,18 @@ public class ReplacementComputeValue implements MethodReplacer {
<section id="beans-factory-scopes-other-injection"> <section id="beans-factory-scopes-other-injection">
<title>Scoped beans as dependencies</title> <title>Scoped beans as dependencies</title>
<para>Being able to define a bean scoped to a HTTP request or <para>Being able to define a bean scoped to an HTTP request or
<interfacename>Session</interfacename> (or indeed <link <interfacename>Session</interfacename> (or indeed <link
linkend="beans-factory-scopes-custom">a custom scope</link> of your linkend="beans-factory-scopes-custom">a custom scope</link> of your
own devising) is all very well, but one of the main value-adds of the own devising) is all very well, but one of the main value-adds of the
Spring IoC container is that it manages not only the instantiation of Spring IoC container is that it manages not only the instantiation of
your objects (beans), but also the wiring up of collaborators (or your objects (beans), but also the wiring up of collaborators (or
dependencies). If you want to inject a (for example) HTTP request dependencies). If you want to inject (for example) an HTTP request
scoped bean into another bean, you will need to inject an AOP proxy in scoped bean into another bean, you will need to inject an AOP proxy in
place of the scoped bean. That is, you need to inject a proxy object place of the scoped bean. That is, you need to inject a proxy object
that exposes the same public interface as the scoped object, but that that exposes the same public interface as the scoped object but that
is smart enough to be able to retrieve the real, target object from is smart enough to be able to retrieve the real, target object from
the relevant scope (for example a HTTP request) and delegate method the relevant scope (for example an HTTP request) and delegate method
calls onto the real object.</para> calls onto the real object.</para>
<note> <note>
@ -3029,7 +3029,7 @@ public class ReplacementComputeValue implements MethodReplacer {
http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"&gt; http://www.springframework.org/schema/aop/spring-aop-3.0.xsd"&gt;
<lineannotation>&lt;!-- a HTTP <interfacename>Session</interfacename>-scoped bean exposed as a proxy --&gt;</lineannotation> <lineannotation>&lt;!-- an HTTP <interfacename>Session</interfacename>-scoped bean exposed as a proxy --&gt;</lineannotation>
&lt;bean id="userPreferences" class="com.foo.UserPreferences" <emphasis &lt;bean id="userPreferences" class="com.foo.UserPreferences" <emphasis
role="bold">scope="session"</emphasis>&gt; role="bold">scope="session"</emphasis>&gt;
@ -3079,12 +3079,12 @@ public class ReplacementComputeValue implements MethodReplacer {
(conceptually) only ever operate on the exact same (conceptually) only ever operate on the exact same
<literal>'userPreferences'</literal> object, that is the one that it <literal>'userPreferences'</literal> object, that is the one that it
was originally injected with. This is <emphasis>not</emphasis> what was originally injected with. This is <emphasis>not</emphasis> what
you want when you inject a HTTP you want when you inject an HTTP
<interfacename>Session</interfacename>-scoped bean as a dependency <interfacename>Session</interfacename>-scoped bean as a dependency
into a collaborating object (typically). Rather, what we into a collaborating object (typically). Rather, what we
<emphasis>do</emphasis> want is a single <emphasis>do</emphasis> want is a single
<literal>'userManager'</literal> object, and then, for the lifetime of <literal>'userManager'</literal> object, and then, for the lifetime of
a HTTP <interfacename>Session</interfacename>, we want to see and use an HTTP <interfacename>Session</interfacename>, we want to see and use
a <literal>'userPreferences'</literal> object that is specific to said a <literal>'userPreferences'</literal> object that is specific to said
HTTP <interfacename>Session</interfacename>.</para> HTTP <interfacename>Session</interfacename>.</para>
@ -3200,7 +3200,7 @@ public class ReplacementComputeValue implements MethodReplacer {
allowing them to be 'destroyed' if needed.</para> allowing them to be 'destroyed' if needed.</para>
<para>The first method should return the object from the underlying <para>The first method should return the object from the underlying
scope. The session scope implementation for example will return the scope. The session scope implementation, for example, will return the
session-scoped bean (and if it does not exist, return a new instance session-scoped bean (and if it does not exist, return a new instance
of the bean, after having bound it to the session for future of the bean, after having bound it to the session for future
reference).</para> reference).</para>
@ -6321,11 +6321,10 @@ public class AppConfig {
<code><link <code><link
linkend="beans-factory-lifecycle-disposablebean">destroy-method</link></code>, linkend="beans-factory-lifecycle-disposablebean">destroy-method</link></code>,
<code><link linkend="beans-factory-autowire">autowiring</link></code> <code><link linkend="beans-factory-autowire">autowiring</link></code>
and <code><link and <code>name</code>.</para>
linkend="beans-factory-scopes">name</link></code>.</para>
<para>You can use the @Bean annotation in a Configuraton-class or in a <para>You can use the <interfacename>@Bean</interfacename> annotation in
Component-class.</para> a Configuration-class or in a Component-class.</para>
<section id="beans-javaconfig-declaring-a-bean"> <section id="beans-javaconfig-declaring-a-bean">
<title>Declaring a bean</title> <title>Declaring a bean</title>
@ -6346,7 +6345,7 @@ public class AppConfig {
return new TransferServiceImpl(); return new TransferServiceImpl();
} }
} </programlisting></para> }</programlisting></para>
<para>For comparison sake, the configuration above is exactly <para>For comparison sake, the configuration above is exactly
equivalent to the following Spring XML: <programlisting equivalent to the following Spring XML: <programlisting
@ -6467,8 +6466,7 @@ public class AppConfig {
<title>Specifying bean scope</title> <title>Specifying bean scope</title>
<section id="beans-javaconfig-available-scopes"> <section id="beans-javaconfig-available-scopes">
<title>Using the <interfacename>@Scope</interfacename> <title>Using the <interfacename>@Scope</interfacename> annotation</title>
annotation</title>
<para>You can specify that your beans defined with the <para>You can specify that your beans defined with the
<interfacename>@Bean</interfacename> annotation should have a <interfacename>@Bean</interfacename> annotation should have a
@ -6476,18 +6474,18 @@ public class AppConfig {
the <link linkend="beans-factory-scopes">Bean Scopes</link> the <link linkend="beans-factory-scopes">Bean Scopes</link>
section.</para> section.</para>
<para>The <code>StandardScopes</code> class provides string <para>The default scope is <literal>"singleton"</literal>, but
constants for each of these four scopes. SINGLETON is the default, this can be overridden by using the
and can be overridden by using the <interfacename>@Scope</interfacename> annotation:
<interfacename>@Scope</interfacename> annotation: <programlisting <programlisting
language="java">@Configuration language="java">@Configuration
public class MyConfiguration { public class MyConfiguration {
@Bean @Bean
@Scope(StandardScopes.PROTOTYPE) <emphasis role="bold">@Scope("prototype")</emphasis>
public Encryptor encryptor() { public Encryptor encryptor() {
// ... // ...
} }
} </programlisting></para> }</programlisting></para>
</section> </section>
<section id="beans-javaconfig-scoped-proxy"> <section id="beans-javaconfig-scoped-proxy">
@ -6507,9 +6505,9 @@ public class MyConfiguration {
<para>If we were to port the the XML reference documentation scoped <para>If we were to port the the XML reference documentation scoped
proxy example (see link above) to our proxy example (see link above) to our
<interfacename>@Bean</interfacename> using Java, it would look like <interfacename>@Bean</interfacename> using Java, it would look like
the following: <programlisting language="java">// a HTTP Session-scoped bean exposed as a proxy the following: <programlisting language="java">// an HTTP Session-scoped bean exposed as a proxy
@Bean @Bean
@Scope(value = StandardScopes.SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS) <emphasis role="bold">@Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)</emphasis>
public UserPreferences userPreferences() { public UserPreferences userPreferences() {
return new UserPreferences(); return new UserPreferences();
} }
@ -6548,10 +6546,10 @@ public Service userService() {
<para>Using Java-configuration support we can easily create a <para>Using Java-configuration support we can easily create a
subclass of <code>CommandManager</code> where the abstract subclass of <code>CommandManager</code> where the abstract
<code>createCommand()</code> is overridden in such a way that it <code>createCommand()</code> method is overridden in such a way that it
'looks up' a brand new (prototype) command object: <programlisting 'looks up' a brand new (prototype) command object: <programlisting
language="java">@Bean language="java">@Bean
@Scope(StandardScopes.PROTOTYPE) @Scope("prototype")
public AsyncCommand asyncCommand() { public AsyncCommand asyncCommand() {
AsyncCommand command = new AsyncCommand(); AsyncCommand command = new AsyncCommand();
// inject dependencies here as required // inject dependencies here as required
@ -6644,12 +6642,12 @@ public class FactoryMethodComponent {
return tb; return tb;
} }
@Bean @Scope(StandardScopes.PROTOTYPE) @Bean @Scope("prototype")
private TestBean privateInstance() { private TestBean privateInstance() {
return new TestBean("privateInstance", i++); return new TestBean("privateInstance", i++);
} }
@Bean @Scope(value = StandardScopes.SESSION, proxyMode = ScopedProxyMode.TARGET_CLASS) @Bean @Scope(value = "session", proxyMode = ScopedProxyMode.TARGET_CLASS)
public TestBean requestScopedInstance() { public TestBean requestScopedInstance() {
return new TestBean("requestScopedInstance", 3); return new TestBean("requestScopedInstance", 3);
} }
@ -6736,11 +6734,11 @@ public class MovieFinderImpl implements MovieFinder {
<para>As with Spring-managed components in general, the default and by <para>As with Spring-managed components in general, the default and by
far most common scope is 'singleton'. However, there are times when far most common scope is 'singleton'. However, there are times when
other scopes are needed. Therefore Spring 2.5 introduces a new other scopes are needed. Therefore Spring 2.5 introduced a new
<interfacename>@Scope</interfacename> annotation as well. Simply provide <interfacename>@Scope</interfacename> annotation as well. Simply provide
the name of the scope within the annotation, such as:</para> the name of the scope within the annotation, such as:</para>
<programlisting language="java">@Scope(StandardScopes.PROTOTYPE) <programlisting language="java"><emphasis role="bold">@Scope("prototype")</emphasis>
@Repository @Repository
public class MovieFinderImpl implements MovieFinder { public class MovieFinderImpl implements MovieFinder {
<lineannotation>// ...</lineannotation> <lineannotation>// ...</lineannotation>