added language element to programlisting for syntax highlighting

This commit is contained in:
Thomas Risberg 2009-04-08 13:38:36 +00:00
parent cfc65b0cc7
commit a3cbb05ed5
6 changed files with 1284 additions and 1249 deletions

View File

@ -33,7 +33,7 @@
is the central interface, used to target advices to particular classes is the central interface, used to target advices to particular classes
and methods. The complete interface is shown below:</para> and methods. The complete interface is shown below:</para>
<programlisting><![CDATA[public interface Pointcut { <programlisting language="java"><![CDATA[public interface Pointcut {
ClassFilter getClassFilter(); ClassFilter getClassFilter();
@ -51,7 +51,7 @@
<literal>matches()</literal> method always returns true, all target <literal>matches()</literal> method always returns true, all target
classes will be matched:</para> classes will be matched:</para>
<programlisting><![CDATA[public interface ClassFilter { <programlisting language="java"><![CDATA[public interface ClassFilter {
boolean matches(Class clazz); boolean matches(Class clazz);
}]]></programlisting> }]]></programlisting>
@ -59,7 +59,7 @@
<para>The <interfacename>MethodMatcher</interfacename> interface is normally more <para>The <interfacename>MethodMatcher</interfacename> interface is normally more
important. The complete interface is shown below:</para> important. The complete interface is shown below:</para>
<programlisting><![CDATA[public interface MethodMatcher { <programlisting language="java"><![CDATA[public interface MethodMatcher {
boolean matches(Method m, Class targetClass); boolean matches(Method m, Class targetClass);
@ -170,7 +170,7 @@
<para>The usage is shown below:</para> <para>The usage is shown below:</para>
<para><programlisting>&lt;bean id="settersAndAbsquatulatePointcut" <para><programlisting language="xml">&lt;bean id="settersAndAbsquatulatePointcut"
class="org.springframework.aop.support.Perl5RegexpMethodPointcut"&gt; class="org.springframework.aop.support.Perl5RegexpMethodPointcut"&gt;
&lt;property name="patterns"&gt; &lt;property name="patterns"&gt;
&lt;list&gt; &lt;list&gt;
@ -189,7 +189,7 @@
as the one bean encapsulates both pointcut and advice, as shown as the one bean encapsulates both pointcut and advice, as shown
below:</para> below:</para>
<para><programlisting>&lt;bean id="settersAndAbsquatulateAdvisor" <para><programlisting language="xml">&lt;bean id="settersAndAbsquatulateAdvisor"
class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"&gt; class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"&gt;
&lt;property name="advice"&gt; &lt;property name="advice"&gt;
&lt;ref local="beanNameOfAopAllianceInterceptor"/&gt; &lt;ref local="beanNameOfAopAllianceInterceptor"/&gt;
@ -260,7 +260,7 @@
just one abstract method (although it's possible to override other just one abstract method (although it's possible to override other
methods to customize behavior):</para> methods to customize behavior):</para>
<para><programlisting>class TestStaticPointcut extends StaticMethodMatcherPointcut { <para><programlisting language="java">class TestStaticPointcut extends StaticMethodMatcherPointcut {
public boolean matches(Method m, Class targetClass) { public boolean matches(Method m, Class targetClass) {
// return true if custom criteria match // return true if custom criteria match
@ -332,7 +332,7 @@
advice using method interception. MethodInterceptors implementing advice using method interception. MethodInterceptors implementing
around advice should implement the following interface:</para> around advice should implement the following interface:</para>
<programlisting>public interface MethodInterceptor extends Interceptor { <programlisting language="java">public interface MethodInterceptor extends Interceptor {
Object invoke(MethodInvocation invocation) throws Throwable; Object invoke(MethodInvocation invocation) throws Throwable;
}</programlisting> }</programlisting>
@ -346,7 +346,7 @@
<para>A simple <classname>MethodInterceptor</classname> implementation <para>A simple <classname>MethodInterceptor</classname> implementation
looks as follows:</para> looks as follows:</para>
<programlisting>public class DebugInterceptor implements MethodInterceptor { <programlisting language="java">public class DebugInterceptor implements MethodInterceptor {
public Object invoke(MethodInvocation invocation) throws Throwable { public Object invoke(MethodInvocation invocation) throws Throwable {
System.out.println("Before: invocation=[" + invocation + "]"); System.out.println("Before: invocation=[" + invocation + "]");
@ -393,7 +393,7 @@
although the usual objects apply to field interception and it's although the usual objects apply to field interception and it's
unlikely that Spring will ever implement it).</para> unlikely that Spring will ever implement it).</para>
<programlisting>public interface MethodBeforeAdvice extends BeforeAdvice { <programlisting language="java">public interface MethodBeforeAdvice extends BeforeAdvice {
void before(Method m, Object[] args, Object target) throws Throwable; void before(Method m, Object[] args, Object target) throws Throwable;
}</programlisting> }</programlisting>
@ -410,7 +410,7 @@
<para>An example of a before advice in Spring, which counts all method <para>An example of a before advice in Spring, which counts all method
invocations:</para> invocations:</para>
<programlisting>public class CountingBeforeAdvice implements MethodBeforeAdvice { <programlisting language="java">public class CountingBeforeAdvice implements MethodBeforeAdvice {
private int count; private int count;
@ -437,7 +437,7 @@
given object implements one or more typed throws advice methods. These given object implements one or more typed throws advice methods. These
should be in the form of:</para> should be in the form of:</para>
<programlisting>afterThrowing([Method, args, target], subclassOfThrowable) </programlisting> <programlisting language="java">afterThrowing([Method, args, target], subclassOfThrowable) </programlisting>
<para>Only the last argument is required. The method signatures may <para>Only the last argument is required. The method signatures may
have either one or four arguments, depending on whether the advice have either one or four arguments, depending on whether the advice
@ -447,7 +447,7 @@
<para>The advice below is invoked if a <exceptionname>RemoteException</exceptionname> <para>The advice below is invoked if a <exceptionname>RemoteException</exceptionname>
is thrown (including subclasses):</para> is thrown (including subclasses):</para>
<programlisting><![CDATA[public class RemoteThrowsAdvice implements ThrowsAdvice { <programlisting language="java"><![CDATA[public class RemoteThrowsAdvice implements ThrowsAdvice {
public void afterThrowing(RemoteException ex) throws Throwable { public void afterThrowing(RemoteException ex) throws Throwable {
]]><lineannotation>// Do something with remote exception</lineannotation><![CDATA[ ]]><lineannotation>// Do something with remote exception</lineannotation><![CDATA[
@ -459,7 +459,7 @@
advice, it declares 4 arguments, so that it has access to the invoked advice, it declares 4 arguments, so that it has access to the invoked
method, method arguments and target object:</para> method, method arguments and target object:</para>
<programlisting><![CDATA[public class ServletThrowsAdviceWithArguments implements ThrowsAdvice { <programlisting language="java"><![CDATA[public class ServletThrowsAdviceWithArguments implements ThrowsAdvice {
public void afterThrowing(Method m, Object[] args, Object target, ServletException ex) { public void afterThrowing(Method m, Object[] args, Object target, ServletException ex) {
]]><lineannotation>// Do something with all arguments</lineannotation><![CDATA[ ]]><lineannotation>// Do something with all arguments</lineannotation><![CDATA[
@ -472,7 +472,7 @@
<literal>ServletException</literal>. Any number of throws advice <literal>ServletException</literal>. Any number of throws advice
methods can be combined in a single class.</para> methods can be combined in a single class.</para>
<programlisting>public static class CombinedThrowsAdvice implements ThrowsAdvice { <programlisting language="java">public static class CombinedThrowsAdvice implements ThrowsAdvice {
public void afterThrowing(RemoteException ex) throws Throwable { public void afterThrowing(RemoteException ex) throws Throwable {
// Do something with remote exception // Do something with remote exception
@ -501,7 +501,7 @@
<emphasis>org.springframework.aop.AfterReturningAdvice</emphasis> <emphasis>org.springframework.aop.AfterReturningAdvice</emphasis>
interface, shown below:</para> interface, shown below:</para>
<programlisting>public interface AfterReturningAdvice extends Advice { <programlisting language="java">public interface AfterReturningAdvice extends Advice {
void afterReturning(Object returnValue, Method m, Object[] args, Object target) void afterReturning(Object returnValue, Method m, Object[] args, Object target)
throws Throwable; throws Throwable;
@ -514,7 +514,7 @@
<para>The following after returning advice counts all successful <para>The following after returning advice counts all successful
method invocations that have not thrown exceptions:</para> method invocations that have not thrown exceptions:</para>
<programlisting>public class CountingAfterReturningAdvice implements AfterReturningAdvice { <programlisting language="java">public class CountingAfterReturningAdvice implements AfterReturningAdvice {
private int count; private int count;
@ -543,7 +543,7 @@
and an <literal>IntroductionInterceptor</literal>, implementing the and an <literal>IntroductionInterceptor</literal>, implementing the
following interface:</para> following interface:</para>
<programlisting>public interface IntroductionInterceptor extends MethodInterceptor { <programlisting language="java">public interface IntroductionInterceptor extends MethodInterceptor {
boolean implementsInterface(Class intf); boolean implementsInterface(Class intf);
}</programlisting> }</programlisting>
@ -563,7 +563,7 @@
<programlisting>public interface IntroductionAdvisor extends Advisor, IntroductionInfo { <programlisting language="java">public interface IntroductionAdvisor extends Advisor, IntroductionInfo {
ClassFilter getClassFilter(); ClassFilter getClassFilter();
@ -603,7 +603,7 @@ public interface IntroductionInfo {
<para> <para>
<programlisting>public interface Lockable { <programlisting language="java">public interface Lockable {
void lock(); void lock();
void unlock(); void unlock();
boolean locked(); boolean locked();
@ -672,7 +672,7 @@ public interface IntroductionInfo {
<para> <para>
<programlisting>public class LockMixin extends DelegatingIntroductionInterceptor <programlisting language="java">public class LockMixin extends DelegatingIntroductionInterceptor
implements Lockable { implements Lockable {
private boolean locked; private boolean locked;
@ -722,7 +722,7 @@ public interface IntroductionInfo {
<para> <para>
<programlisting>public class LockMixinAdvisor extends DefaultIntroductionAdvisor { <programlisting language="java">public class LockMixinAdvisor extends DefaultIntroductionAdvisor {
public LockMixinAdvisor() { public LockMixinAdvisor() {
super(new LockMixin(), Lockable.class); super(new LockMixin(), Lockable.class);
@ -1032,7 +1032,7 @@ public interface IntroductionInfo {
</listitem> </listitem>
</itemizedlist> </itemizedlist>
<para><programlisting>&lt;bean id="personTarget" class="com.mycompany.PersonImpl"&gt; <para><programlisting language="xml">&lt;bean id="personTarget" class="com.mycompany.PersonImpl"&gt;
&lt;property name="name"&gt;&lt;value&gt;Tony&lt;/value&gt;&lt;/property&gt; &lt;property name="name"&gt;&lt;value&gt;Tony&lt;/value&gt;&lt;/property&gt;
&lt;property name="age"&gt;&lt;value&gt;51&lt;/value&gt;&lt;/property&gt; &lt;property name="age"&gt;&lt;value&gt;51&lt;/value&gt;&lt;/property&gt;
&lt;/bean&gt; &lt;/bean&gt;
@ -1076,12 +1076,12 @@ public interface IntroductionInfo {
<para>The "person" bean definition above can be used in place of a <para>The "person" bean definition above can be used in place of a
Person implementation, as follows:</para> Person implementation, as follows:</para>
<programlisting>Person person = (Person) factory.getBean("person");</programlisting> <programlisting language="java">Person person = (Person) factory.getBean("person");</programlisting>
<para>Other beans in the same IoC context can express a strongly typed <para>Other beans in the same IoC context can express a strongly typed
dependency on it, as with an ordinary Java object:</para> dependency on it, as with an ordinary Java object:</para>
<para><programlisting>&lt;bean id="personUser" class="com.mycompany.PersonUser"&gt; <para><programlisting language="xml">&lt;bean id="personUser" class="com.mycompany.PersonUser"&gt;
&lt;property name="person"&gt;&lt;ref local="person" /&gt;&lt;/property&gt; &lt;property name="person"&gt;&lt;ref local="person" /&gt;&lt;/property&gt;
&lt;/bean&gt;</programlisting></para> &lt;/bean&gt;</programlisting></para>
@ -1097,7 +1097,7 @@ public interface IntroductionInfo {
<literal>ProxyFactoryBean</literal> definition is different; the advice <literal>ProxyFactoryBean</literal> definition is different; the advice
is included only for completeness:</para> is included only for completeness:</para>
<para><programlisting>&lt;bean id="myAdvisor" class="com.mycompany.MyAdvisor"&gt; <para><programlisting language="xml">&lt;bean id="myAdvisor" class="com.mycompany.MyAdvisor"&gt;
&lt;property name="someProperty"&gt;&lt;value&gt;Custom string property value&lt;/value&gt;&lt;/property&gt; &lt;property name="someProperty"&gt;&lt;value&gt;Custom string property value&lt;/value&gt;&lt;/property&gt;
&lt;/bean&gt; &lt;/bean&gt;
@ -1184,7 +1184,7 @@ public interface IntroductionInfo {
<para>By appending an asterisk to an interceptor name, all advisors with <para>By appending an asterisk to an interceptor name, all advisors with
bean names matching the part before the asterisk, will be added to the bean names matching the part before the asterisk, will be added to the
advisor chain. This can come in handy if you need to add a standard set advisor chain. This can come in handy if you need to add a standard set
of 'global' advisors: <programlisting> of 'global' advisors: <programlisting language="xml">
&lt;bean id="proxy" class="org.springframework.aop.framework.ProxyFactoryBean"&gt; &lt;bean id="proxy" class="org.springframework.aop.framework.ProxyFactoryBean"&gt;
&lt;property name="target" ref="service"/&gt; &lt;property name="target" ref="service"/&gt;
&lt;property name="interceptorNames"&gt; &lt;property name="interceptorNames"&gt;
@ -1211,7 +1211,7 @@ public interface IntroductionInfo {
<para>First a parent, <emphasis>template</emphasis>, bean definition is <para>First a parent, <emphasis>template</emphasis>, bean definition is
created for the proxy:</para> created for the proxy:</para>
<para><programlisting>&lt;bean id="txProxyTemplate" abstract="true" <para><programlisting language="xml">&lt;bean id="txProxyTemplate" abstract="true"
class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt; class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"&gt;
&lt;property name="transactionManager" ref="transactionManager"/&gt; &lt;property name="transactionManager" ref="transactionManager"/&gt;
&lt;property name="transactionAttributes"&gt; &lt;property name="transactionAttributes"&gt;
@ -1225,7 +1225,7 @@ public interface IntroductionInfo {
incomplete. Then each proxy which needs to be created is just a child bean incomplete. Then each proxy which needs to be created is just a child bean
definition, which wraps the target of the proxy as an inner bean definition, which wraps the target of the proxy as an inner bean
definition, since the target will never be used on its own definition, since the target will never be used on its own
anyway.<programlisting>&lt;bean id="myService" parent="txProxyTemplate"&gt; anyway.<programlisting language="xml">&lt;bean id="myService" parent="txProxyTemplate"&gt;
&lt;property name="target"&gt; &lt;property name="target"&gt;
&lt;bean class="org.springframework.samples.MyServiceImpl"&gt; &lt;bean class="org.springframework.samples.MyServiceImpl"&gt;
&lt;/bean&gt; &lt;/bean&gt;
@ -1234,7 +1234,7 @@ public interface IntroductionInfo {
<para>It is of course possible to override properties from the parent <para>It is of course possible to override properties from the parent
template, such as in this case, the transaction propagation template, such as in this case, the transaction propagation
settings:<programlisting>&lt;bean id="mySpecialService" parent="txProxyTemplate"&gt; settings:<programlisting language="xml">&lt;bean id="mySpecialService" parent="txProxyTemplate"&gt;
&lt;property name="target"&gt; &lt;property name="target"&gt;
&lt;bean class="org.springframework.samples.MySpecialServiceImpl"&gt; &lt;bean class="org.springframework.samples.MySpecialServiceImpl"&gt;
&lt;/bean&gt; &lt;/bean&gt;
@ -1273,7 +1273,7 @@ public interface IntroductionInfo {
with one interceptor and one advisor. The interfaces implemented by the with one interceptor and one advisor. The interfaces implemented by the
target object will automatically be proxied:</para> target object will automatically be proxied:</para>
<para><programlisting>ProxyFactory factory = new ProxyFactory(myBusinessInterfaceImpl); <para><programlisting language="java">ProxyFactory factory = new ProxyFactory(myBusinessInterfaceImpl);
factory.addInterceptor(myMethodInterceptor); factory.addInterceptor(myMethodInterceptor);
factory.addAdvisor(myAdvisor); factory.addAdvisor(myAdvisor);
MyBusinessInterface tb = (MyBusinessInterface) factory.getProxy();</programlisting></para> MyBusinessInterface tb = (MyBusinessInterface) factory.getProxy();</programlisting></para>
@ -1308,7 +1308,7 @@ MyBusinessInterface tb = (MyBusinessInterface) factory.getProxy();</programlisti
Any AOP proxy can be cast to this interface, whichever other interfaces it Any AOP proxy can be cast to this interface, whichever other interfaces it
implements. This interface includes the following methods:</para> implements. This interface includes the following methods:</para>
<programlisting>Advisor[] getAdvisors(); <programlisting language="java">Advisor[] getAdvisors();
void addAdvice(Advice advice) throws AopConfigException; void addAdvice(Advice advice) throws AopConfigException;
@ -1355,7 +1355,7 @@ boolean isFrozen();</programlisting>
<literal>Advised</literal> interface and examining and manipulating its <literal>Advised</literal> interface and examining and manipulating its
advice:</para> advice:</para>
<para><programlisting>Advised advised = (Advised) myObject; <para><programlisting language="java">Advised advised = (Advised) myObject;
Advisor[] advisors = advised.getAdvisors(); Advisor[] advisors = advised.getAdvisors();
int oldAdvisorCount = advisors.length; int oldAdvisorCount = advisors.length;
System.out.println(oldAdvisorCount + " advisors"); System.out.println(oldAdvisorCount + " advisors");
@ -1438,7 +1438,7 @@ assertEquals("Added two advisors",
<literal>BeanPostProcessor</literal> that automatically creates AOP proxies <literal>BeanPostProcessor</literal> that automatically creates AOP proxies
for beans with names matching literal values or wildcards.</para> for beans with names matching literal values or wildcards.</para>
<para><programlisting>&lt;bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"&gt; <para><programlisting language="xml">&lt;bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"&gt;
&lt;property name="beanNames"&gt;&lt;value&gt;jdk*,onlyJdk&lt;/value&gt;&lt;/property&gt; &lt;property name="beanNames"&gt;&lt;value&gt;jdk*,onlyJdk&lt;/value&gt;&lt;/property&gt;
&lt;property name="interceptorNames"&gt; &lt;property name="interceptorNames"&gt;
&lt;list&gt; &lt;list&gt;
@ -1513,7 +1513,7 @@ assertEquals("Added two advisors",
return an AOP proxy, not the target business object. (The "inner bean" return an AOP proxy, not the target business object. (The "inner bean"
idiom shown earlier also offers this benefit.)</para> idiom shown earlier also offers this benefit.)</para>
<para><programlisting>&lt;bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/&gt; <para><programlisting language="xml">&lt;bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/&gt;
&lt;bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"&gt; &lt;bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"&gt;
&lt;property name="transactionInterceptor" ref="transactionInterceptor"/&gt; &lt;property name="transactionInterceptor" ref="transactionInterceptor"/&gt;
@ -1586,7 +1586,7 @@ assertEquals("Added two advisors",
following code, in <literal>/WEB-INF/declarativeServices.xml</literal>. following code, in <literal>/WEB-INF/declarativeServices.xml</literal>.
Note that this is generic, and can be used outside the JPetStore:</para> Note that this is generic, and can be used outside the JPetStore:</para>
<para><programlisting>&lt;bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/&gt; <para><programlisting language="xml">&lt;bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/&gt;
&lt;bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"&gt; &lt;bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"&gt;
&lt;property name="transactionInterceptor" ref="transactionInterceptor"/&gt; &lt;property name="transactionInterceptor" ref="transactionInterceptor"/&gt;
@ -1627,7 +1627,7 @@ assertEquals("Added two advisors",
annotation, leading to implicit proxies for beans containing that annotation, leading to implicit proxies for beans containing that
annotation:</para> annotation:</para>
<para><programlisting>&lt;bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/&gt; <para><programlisting language="xml">&lt;bean class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"/&gt;
&lt;bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"&gt; &lt;bean class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"&gt;
&lt;property name="transactionInterceptor" ref="transactionInterceptor"/&gt; &lt;property name="transactionInterceptor" ref="transactionInterceptor"/&gt;
@ -1647,7 +1647,7 @@ assertEquals("Added two advisors",
be specific to the application's transaction requirements (typically be specific to the application's transaction requirements (typically
JTA, as in this example, or Hibernate, JDO or JDBC):</para> JTA, as in this example, or Hibernate, JDO or JDBC):</para>
<programlisting>&lt;bean id="transactionManager" <programlisting language="xml">&lt;bean id="transactionManager"
class="org.springframework.transaction.jta.JtaTransactionManager"/&gt;</programlisting> class="org.springframework.transaction.jta.JtaTransactionManager"/&gt;</programlisting>
<tip> <tip>
@ -1684,7 +1684,7 @@ assertEquals("Added two advisors",
generic <literal>DefaultPointcutAdvisor</literal>, configured using generic <literal>DefaultPointcutAdvisor</literal>, configured using
JavaBean properties:</para> JavaBean properties:</para>
<para><programlisting>&lt;bean id="lockMixin" class="org.springframework.aop.LockMixin" <para><programlisting language="xml">&lt;bean id="lockMixin" class="org.springframework.aop.LockMixin"
scope="prototype"/&gt; scope="prototype"/&gt;
&lt;bean id="lockableAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor" &lt;bean id="lockableAdvisor" class="org.springframework.aop.support.DefaultPointcutAdvisor"
@ -1748,13 +1748,13 @@ assertEquals("Added two advisors",
<para>You can change the target via the <literal>swap()</literal> method <para>You can change the target via the <literal>swap()</literal> method
on HotSwappableTargetSource as follows:</para> on HotSwappableTargetSource as follows:</para>
<para><programlisting>HotSwappableTargetSource swapper = <para><programlisting language="java">HotSwappableTargetSource swapper =
(HotSwappableTargetSource) beanFactory.getBean("swapper"); (HotSwappableTargetSource) beanFactory.getBean("swapper");
Object oldTarget = swapper.swap(newTarget);</programlisting></para> Object oldTarget = swapper.swap(newTarget);</programlisting></para>
<para>The XML definitions required look as follows:</para> <para>The XML definitions required look as follows:</para>
<para><programlisting>&lt;bean id="initialTarget" class="mycompany.OldTarget"/&gt; <para><programlisting language="xml">&lt;bean id="initialTarget" class="mycompany.OldTarget"/&gt;
&lt;bean id="swapper" class="org.springframework.aop.target.HotSwappableTargetSource"&gt; &lt;bean id="swapper" class="org.springframework.aop.target.HotSwappableTargetSource"&gt;
&lt;constructor-arg ref="initialTarget"/&gt; &lt;constructor-arg ref="initialTarget"/&gt;
@ -1796,7 +1796,7 @@ Object oldTarget = swapper.swap(newTarget);</programlisting></para>
<para>Sample configuration is shown below:</para> <para>Sample configuration is shown below:</para>
<para><programlisting>&lt;bean id="businessObjectTarget" class="com.mycompany.MyBusinessObject" <para><programlisting language="xml">&lt;bean id="businessObjectTarget" class="com.mycompany.MyBusinessObject"
scope="prototype"&gt; scope="prototype"&gt;
... properties omitted ... properties omitted
&lt;/bean&gt; &lt;/bean&gt;
@ -1832,7 +1832,7 @@ Object oldTarget = swapper.swap(newTarget);</programlisting></para>
size of the pool through an introduction. You'll need to define an size of the pool through an introduction. You'll need to define an
advisor like this:</para> advisor like this:</para>
<para><programlisting>&lt;bean id="poolConfigAdvisor" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"&gt; <para><programlisting language="xml">&lt;bean id="poolConfigAdvisor" class="org.springframework.beans.factory.config.MethodInvokingFactoryBean"&gt;
&lt;property name="targetObject" ref="poolTargetSource"/&gt; &lt;property name="targetObject" ref="poolTargetSource"/&gt;
&lt;property name="targetMethod" value="getPoolingConfigMixin"/&gt; &lt;property name="targetMethod" value="getPoolingConfigMixin"/&gt;
&lt;/bean&gt;</programlisting></para> &lt;/bean&gt;</programlisting></para>
@ -1845,7 +1845,7 @@ Object oldTarget = swapper.swap(newTarget);</programlisting></para>
<para>The cast will look as follows:</para> <para>The cast will look as follows:</para>
<programlisting><![CDATA[PoolingConfig conf = (PoolingConfig) beanFactory.getBean("businessObject"); <programlisting language="java"><![CDATA[PoolingConfig conf = (PoolingConfig) beanFactory.getBean("businessObject");
System.out.println("Max pool size is " + conf.getMaxSize());]]></programlisting> System.out.println("Max pool size is " + conf.getMaxSize());]]></programlisting>
<note> <note>
@ -1873,7 +1873,7 @@ System.out.println("Max pool size is " + conf.getMaxSize());]]></programlisting>
<literal>poolTargetSource</literal> definition shown above as follows. <literal>poolTargetSource</literal> definition shown above as follows.
(I've also changed the name, for clarity.)</para> (I've also changed the name, for clarity.)</para>
<programlisting><![CDATA[<bean id="prototypeTargetSource" class="org.springframework.aop.target.PrototypeTargetSource"> <programlisting language="xml"><![CDATA[<bean id="prototypeTargetSource" class="org.springframework.aop.target.PrototypeTargetSource">
<property name="targetBeanName" ref="businessObjectTarget"/> <property name="targetBeanName" ref="businessObjectTarget"/>
</bean>]]></programlisting> </bean>]]></programlisting>
@ -1893,7 +1893,7 @@ System.out.println("Max pool size is " + conf.getMaxSize());]]></programlisting>
<classname>ThreadLocalTargetSource</classname> is pretty much the same as was explained for the <classname>ThreadLocalTargetSource</classname> is pretty much the same as was explained for the
other types of target source:</para> other types of target source:</para>
<programlisting><![CDATA[<bean id="threadlocalTargetSource" class="org.springframework.aop.target.ThreadLocalTargetSource"> <programlisting language="xml"><![CDATA[<bean id="threadlocalTargetSource" class="org.springframework.aop.target.ThreadLocalTargetSource">
<property name="targetBeanName" value="businessObjectTarget"/> <property name="targetBeanName" value="businessObjectTarget"/>
</bean>]]></programlisting> </bean>]]></programlisting>

View File

@ -327,7 +327,7 @@
<para>The @AspectJ support is enabled by including the following element <para>The @AspectJ support is enabled by including the following element
inside your spring configuration:</para> inside your spring configuration:</para>
<programlisting>&lt;aop:aspectj-autoproxy/&gt;</programlisting> <programlisting language="xml">&lt;aop:aspectj-autoproxy/&gt;</programlisting>
<para>This assumes that you are using schema support as described in <para>This assumes that you are using schema support as described in
<xref linkend="xsd-config" />. See <xref <xref linkend="xsd-config" />. See <xref
@ -338,7 +338,7 @@
support by adding the following definition to your application support by adding the following definition to your application
context:</para> context:</para>
<programlisting>&lt;bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" /&gt;</programlisting> <programlisting language="xml">&lt;bean class="org.springframework.aop.aspectj.annotation.AnnotationAwareAspectJAutoProxyCreator" /&gt;</programlisting>
<para>You will also need two AspectJ libraries on the classpath of your <para>You will also need two AspectJ libraries on the classpath of your
application: <filename class="libraryfile">aspectjweaver.jar</filename> application: <filename class="libraryfile">aspectjweaver.jar</filename>
@ -364,7 +364,7 @@
a bean class that has the <interfacename>@Aspect</interfacename> a bean class that has the <interfacename>@Aspect</interfacename>
annotation:</para> annotation:</para>
<programlisting>&lt;bean id="myAspect" class="org.xyz.NotVeryUsefulAspect"&gt; <programlisting language="xml">&lt;bean id="myAspect" class="org.xyz.NotVeryUsefulAspect"&gt;
<lineannotation>&lt;!-- configure properties of aspect here as normal --&gt;</lineannotation> <lineannotation>&lt;!-- configure properties of aspect here as normal --&gt;</lineannotation>
&lt;/bean&gt; &lt;/bean&gt;
</programlisting> </programlisting>
@ -374,7 +374,7 @@
<interfacename>org.aspectj.lang.annotation.Aspect</interfacename> <interfacename>org.aspectj.lang.annotation.Aspect</interfacename>
annotation;</para> annotation;</para>
<programlisting>package org.xyz; <programlisting language="java">package org.xyz;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
@Aspect @Aspect
@ -419,7 +419,7 @@ public class NotVeryUsefulAspect {
a pointcut named <literal>'anyOldTransfer'</literal> that will match the a pointcut named <literal>'anyOldTransfer'</literal> that will match the
execution of any method named <literal>'transfer'</literal>:</para> execution of any method named <literal>'transfer'</literal>:</para>
<programlisting>@Pointcut("execution(* transfer(..))")<lineannotation>// the pointcut expression</lineannotation> <programlisting language="java">@Pointcut("execution(* transfer(..))")<lineannotation>// the pointcut expression</lineannotation>
private void anyOldTransfer() {}<lineannotation>// the pointcut signature</lineannotation></programlisting> private void anyOldTransfer() {}<lineannotation>// the pointcut signature</lineannotation></programlisting>
<para>The pointcut expression that forms the value of the <para>The pointcut expression that forms the value of the
@ -550,7 +550,7 @@ private void anyOldTransfer() {}<lineannotation>// the pointcut signature</linea
Spring beans (when using wildcards). The '<literal>bean</literal>' PCD Spring beans (when using wildcards). The '<literal>bean</literal>' PCD
has the following form:</para> has the following form:</para>
<programlisting>bean(idOrNameOfBean)</programlisting> <programlisting language="java">bean(idOrNameOfBean)</programlisting>
<para>The '<literal>idOrNameOfBean</literal>' token can be the name of <para>The '<literal>idOrNameOfBean</literal>' token can be the name of
any Spring bean: limited wildcard support using the any Spring bean: limited wildcard support using the
@ -592,7 +592,7 @@ private void anyOldTransfer() {}<lineannotation>// the pointcut signature</linea
matches if a method execution represents any public method in the matches if a method execution represents any public method in the
trading module).</para> trading module).</para>
<programlisting> @Pointcut("execution(public * *(..))") <programlisting language="java"> @Pointcut("execution(public * *(..))")
private void anyPublicOperation() {} private void anyPublicOperation() {}
@Pointcut("within(com.xyz.someapp.trading..*)") @Pointcut("within(com.xyz.someapp.trading..*)")
@ -618,7 +618,7 @@ private void anyOldTransfer() {}<lineannotation>// the pointcut signature</linea
"SystemArchitecture" aspect that captures common pointcut expressions "SystemArchitecture" aspect that captures common pointcut expressions
for this purpose. A typical such aspect would look as follows:</para> for this purpose. A typical such aspect would look as follows:</para>
<programlisting>package com.xyz.someapp; <programlisting language="java">package com.xyz.someapp;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut; import org.aspectj.lang.annotation.Pointcut;
@ -681,7 +681,7 @@ public class SystemArchitecture {
anywhere that you need a pointcut expression. For example, to make the anywhere that you need a pointcut expression. For example, to make the
service layer transactional, you could write:</para> service layer transactional, you could write:</para>
<programlisting>&lt;aop:config&gt; <programlisting language="xml">&lt;aop:config&gt;
&lt;aop:advisor &lt;aop:advisor
pointcut="com.xyz.someapp.SystemArchitecture.businessService()" pointcut="com.xyz.someapp.SystemArchitecture.businessService()"
advice-ref="tx-advice"/&gt; advice-ref="tx-advice"/&gt;
@ -706,7 +706,7 @@ public class SystemArchitecture {
<literal>execution</literal> pointcut designator the most often. The <literal>execution</literal> pointcut designator the most often. The
format of an execution expression is:</para> format of an execution expression is:</para>
<programlisting>execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern) <programlisting language="java">execution(modifiers-pattern? ret-type-pattern declaring-type-pattern? name-pattern(param-pattern)
throws-pattern?)</programlisting> throws-pattern?)</programlisting>
<para>All parts except the returning type pattern (ret-type-pattern in <para>All parts except the returning type pattern (ret-type-pattern in
@ -736,49 +736,49 @@ public class SystemArchitecture {
<listitem> <listitem>
<para>the execution of any public method:</para> <para>the execution of any public method:</para>
<programlisting>execution(public * *(..))</programlisting> <programlisting language="java">execution(public * *(..))</programlisting>
</listitem> </listitem>
<listitem> <listitem>
<para>the execution of any method with a name beginning with <para>the execution of any method with a name beginning with
"set":</para> "set":</para>
<programlisting>execution(* set*(..))</programlisting> <programlisting language="java">execution(* set*(..))</programlisting>
</listitem> </listitem>
<listitem> <listitem>
<para>the execution of any method defined by the <para>the execution of any method defined by the
<interfacename>AccountService</interfacename> interface:</para> <interfacename>AccountService</interfacename> interface:</para>
<programlisting>execution(* com.xyz.service.AccountService.*(..))</programlisting> <programlisting language="java">execution(* com.xyz.service.AccountService.*(..))</programlisting>
</listitem> </listitem>
<listitem> <listitem>
<para>the execution of any method defined in the service <para>the execution of any method defined in the service
package:</para> package:</para>
<programlisting>execution(* com.xyz.service.*.*(..))</programlisting> <programlisting language="java">execution(* com.xyz.service.*.*(..))</programlisting>
</listitem> </listitem>
<listitem> <listitem>
<para>the execution of any method defined in the service package <para>the execution of any method defined in the service package
or a sub-package:</para> or a sub-package:</para>
<programlisting>execution(* com.xyz.service..*.*(..))</programlisting> <programlisting language="java">execution(* com.xyz.service..*.*(..))</programlisting>
</listitem> </listitem>
<listitem> <listitem>
<para>any join point (method execution only in Spring AOP) within <para>any join point (method execution only in Spring AOP) within
the service package:</para> the service package:</para>
<programlisting>within(com.xyz.service.*)</programlisting> <programlisting language="java">within(com.xyz.service.*)</programlisting>
</listitem> </listitem>
<listitem> <listitem>
<para>any join point (method execution only in Spring AOP) within <para>any join point (method execution only in Spring AOP) within
the service package or a sub-package:</para> the service package or a sub-package:</para>
<programlisting>within(com.xyz.service..*)</programlisting> <programlisting language="java">within(com.xyz.service..*)</programlisting>
</listitem> </listitem>
<listitem> <listitem>
@ -786,7 +786,7 @@ public class SystemArchitecture {
the proxy implements the the proxy implements the
<interfacename>AccountService</interfacename> interface:</para> <interfacename>AccountService</interfacename> interface:</para>
<programlisting>this(com.xyz.service.AccountService)</programlisting> <programlisting language="java">this(com.xyz.service.AccountService)</programlisting>
<remark><para>'this' is more commonly used in a binding form :- <remark><para>'this' is more commonly used in a binding form :-
see the following section on advice for how to make the proxy see the following section on advice for how to make the proxy
@ -798,7 +798,7 @@ public class SystemArchitecture {
the target object implements the the target object implements the
<interfacename>AccountService</interfacename> interface:</para> <interfacename>AccountService</interfacename> interface:</para>
<programlisting>target(com.xyz.service.AccountService)</programlisting> <programlisting language="java">target(com.xyz.service.AccountService)</programlisting>
<remark><para>'target' is more commonly used in a binding form :- <remark><para>'target' is more commonly used in a binding form :-
see the following section on advice for how to make the target see the following section on advice for how to make the target
@ -810,7 +810,7 @@ public class SystemArchitecture {
takes a single parameter, and where the argument passed at runtime takes a single parameter, and where the argument passed at runtime
is <interfacename>Serializable</interfacename>:</para> is <interfacename>Serializable</interfacename>:</para>
<programlisting>args(java.io.Serializable)</programlisting> <programlisting language="java">args(java.io.Serializable)</programlisting>
<remark>'args' is more commonly used in a binding form :- see the <remark>'args' is more commonly used in a binding form :- see the
following section on advice for how to make the method arguments following section on advice for how to make the method arguments
@ -829,7 +829,7 @@ public class SystemArchitecture {
the target object has an the target object has an
<interfacename>@Transactional</interfacename> annotation:</para> <interfacename>@Transactional</interfacename> annotation:</para>
<programlisting>@target(org.springframework.transaction.annotation.Transactional)</programlisting> <programlisting language="java">@target(org.springframework.transaction.annotation.Transactional)</programlisting>
<remark><para>'@target' can also be used in a binding form :- see <remark><para>'@target' can also be used in a binding form :- see
the following section on advice for how to make the annotation the following section on advice for how to make the annotation
@ -841,7 +841,7 @@ public class SystemArchitecture {
the declared type of the target object has an the declared type of the target object has an
<interfacename>@Transactional</interfacename> annotation:</para> <interfacename>@Transactional</interfacename> annotation:</para>
<programlisting>@within(org.springframework.transaction.annotation.Transactional)</programlisting> <programlisting language="java">@within(org.springframework.transaction.annotation.Transactional)</programlisting>
<remark><para>'@within' can also be used in a binding form :- see <remark><para>'@within' can also be used in a binding form :- see
the following section on advice for how to make the annotation the following section on advice for how to make the annotation
@ -853,7 +853,7 @@ public class SystemArchitecture {
the executing method has an the executing method has an
<interfacename>@Transactional</interfacename> annotation:</para> <interfacename>@Transactional</interfacename> annotation:</para>
<programlisting>@annotation(org.springframework.transaction.annotation.Transactional)</programlisting> <programlisting language="java">@annotation(org.springframework.transaction.annotation.Transactional)</programlisting>
<remark><para>'@annotation' can also be used in a binding form :- <remark><para>'@annotation' can also be used in a binding form :-
see the following section on advice for how to make the annotation see the following section on advice for how to make the annotation
@ -866,7 +866,7 @@ public class SystemArchitecture {
argument passed has the <interfacename>@Classified</interfacename> argument passed has the <interfacename>@Classified</interfacename>
annotation:</para> annotation:</para>
<programlisting>@args(com.xyz.security.Classified)</programlisting> <programlisting language="java">@args(com.xyz.security.Classified)</programlisting>
<remark><para>'@args' can also be used in a binding form :- see <remark><para>'@args' can also be used in a binding form :- see
the following section on advice for how to make the annotation the following section on advice for how to make the annotation
@ -877,7 +877,7 @@ public class SystemArchitecture {
<para>any join point (method execution only in Spring AOP) on a <para>any join point (method execution only in Spring AOP) on a
Spring bean named '<literal>tradeService</literal>':</para> Spring bean named '<literal>tradeService</literal>':</para>
<programlisting>bean(tradeService)</programlisting> <programlisting language="java">bean(tradeService)</programlisting>
</listitem> </listitem>
<listitem> <listitem>
@ -885,7 +885,7 @@ public class SystemArchitecture {
Spring beans having names that match the wildcard expression Spring beans having names that match the wildcard expression
'<literal>*Service</literal>':</para> '<literal>*Service</literal>':</para>
<programlisting>bean(*Service)</programlisting> <programlisting language="java">bean(*Service)</programlisting>
</listitem> </listitem>
</itemizedlist> </itemizedlist>
</section> </section>
@ -905,7 +905,7 @@ public class SystemArchitecture {
<para>Before advice is declared in an aspect using the <para>Before advice is declared in an aspect using the
<interfacename>@Before</interfacename> annotation:</para> <interfacename>@Before</interfacename> annotation:</para>
<programlisting>import org.aspectj.lang.annotation.Aspect; <programlisting language="java">import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
@Aspect @Aspect
@ -921,7 +921,7 @@ public class BeforeExample {
<para>If using an in-place pointcut expression we could rewrite the <para>If using an in-place pointcut expression we could rewrite the
above example as:</para> above example as:</para>
<programlisting>import org.aspectj.lang.annotation.Aspect; <programlisting language="java">import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Before; import org.aspectj.lang.annotation.Before;
@Aspect @Aspect
@ -942,7 +942,7 @@ public class BeforeExample {
returns normally. It is declared using the returns normally. It is declared using the
<interfacename>@AfterReturning</interfacename> annotation:</para> <interfacename>@AfterReturning</interfacename> annotation:</para>
<programlisting>import org.aspectj.lang.annotation.Aspect; <programlisting language="java">import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.AfterReturning;
@Aspect @Aspect
@ -965,7 +965,7 @@ public class AfterReturningExample {
<interfacename>@AfterReturning</interfacename> that binds the return <interfacename>@AfterReturning</interfacename> that binds the return
value for this:</para> value for this:</para>
<programlisting>import org.aspectj.lang.annotation.Aspect; <programlisting language="java">import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.AfterReturning; import org.aspectj.lang.annotation.AfterReturning;
@Aspect @Aspect
@ -1001,7 +1001,7 @@ public class AfterReturningExample {
by throwing an exception. It is declared using the by throwing an exception. It is declared using the
<interfacename>@AfterThrowing</interfacename> annotation:</para> <interfacename>@AfterThrowing</interfacename> annotation:</para>
<programlisting>import org.aspectj.lang.annotation.Aspect; <programlisting language="java">import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.AfterThrowing;
@Aspect @Aspect
@ -1022,7 +1022,7 @@ public class AfterThrowingExample {
otherwise) and bind the thrown exception to an advice otherwise) and bind the thrown exception to an advice
parameter.</para> parameter.</para>
<programlisting>import org.aspectj.lang.annotation.Aspect; <programlisting language="java">import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.AfterThrowing; import org.aspectj.lang.annotation.AfterThrowing;
@Aspect @Aspect
@ -1055,7 +1055,7 @@ public class AfterThrowingExample {
exception return conditions. It is typically used for releasing exception return conditions. It is typically used for releasing
resources, etc.</para> resources, etc.</para>
<programlisting>import org.aspectj.lang.annotation.Aspect; <programlisting language="java">import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.After; import org.aspectj.lang.annotation.After;
@Aspect @Aspect
@ -1111,7 +1111,7 @@ public class AfterFinallyExample {
AspectJ, and this is discussed in the following section on advice AspectJ, and this is discussed in the following section on advice
parameters.</remark> parameters.</remark>
<programlisting>import org.aspectj.lang.annotation.Aspect; <programlisting language="java">import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Around; import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
@ -1184,7 +1184,7 @@ public class AroundExample {
Account object as the first parameter, and you need access to the Account object as the first parameter, and you need access to the
account in the advice body. You could write the following:</para> account in the advice body. You could write the following:</para>
<programlisting>@Before("com.xyz.myapp.SystemArchitecture.dataAccessOperation() &amp;&amp;" + <programlisting language="java">@Before("com.xyz.myapp.SystemArchitecture.dataAccessOperation() &amp;&amp;" +
"args(account,..)") "args(account,..)")
public void validateAccount(Account account) { public void validateAccount(Account account) {
<lineannotation>// ...</lineannotation> <lineannotation>// ...</lineannotation>
@ -1203,7 +1203,7 @@ public void validateAccount(Account account) {
matches a join point, and then just refer to the named pointcut from matches a join point, and then just refer to the named pointcut from
the advice. This would look as follows:</para> the advice. This would look as follows:</para>
<programlisting>@Pointcut("com.xyz.myapp.SystemArchitecture.dataAccessOperation() &amp;&amp;" + <programlisting language="java">@Pointcut("com.xyz.myapp.SystemArchitecture.dataAccessOperation() &amp;&amp;" +
"args(account,..)") "args(account,..)")
private void accountDataAccessOperation(Account account) {} private void accountDataAccessOperation(Account account) {}
@ -1226,7 +1226,7 @@ public void validateAccount(Account account) {
<para>First the definition of the <para>First the definition of the
<interfacename>@Auditable</interfacename> annotation:</para> <interfacename>@Auditable</interfacename> annotation:</para>
<programlisting>@Retention(RetentionPolicy.RUNTIME) <programlisting language="java">@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD) @Target(ElementType.METHOD)
public @interface Auditable { public @interface Auditable {
AuditCode value(); AuditCode value();
@ -1235,7 +1235,7 @@ public @interface Auditable {
<para>And then the advice that matches the execution of <para>And then the advice that matches the execution of
<interfacename>@Auditable</interfacename> methods:</para> <interfacename>@Auditable</interfacename> methods:</para>
<programlisting>@Before("com.xyz.lib.Pointcuts.anyPublicMethod() &amp;&amp; " + <programlisting language="java">@Before("com.xyz.lib.Pointcuts.anyPublicMethod() &amp;&amp; " +
"@annotation(auditable)") "@annotation(auditable)")
public void audit(Auditable auditable) { public void audit(Auditable auditable) {
AuditCode code = auditable.value(); AuditCode code = auditable.value();
@ -1263,7 +1263,7 @@ public void audit(Auditable auditable) {
<emphasis>are</emphasis> available at runtime. For <emphasis>are</emphasis> available at runtime. For
example:</para> example:</para>
<programlisting>@Before( <programlisting language="java">@Before(
value="com.xyz.lib.Pointcuts.anyPublicMethod() &amp;&amp; target(bean) &amp;&amp; @annotation(auditable)", value="com.xyz.lib.Pointcuts.anyPublicMethod() &amp;&amp; target(bean) &amp;&amp; @annotation(auditable)",
argNames="bean,auditable") argNames="bean,auditable")
public void audit(Object bean, Auditable auditable) { public void audit(Object bean, Auditable auditable) {
@ -1280,7 +1280,7 @@ public void audit(Object bean, Auditable auditable) {
advice to receive the join point object, the "argNames" advice to receive the join point object, the "argNames"
attribute need not include it:</para> attribute need not include it:</para>
<programlisting>@Before( <programlisting language="java">@Before(
value="com.xyz.lib.Pointcuts.anyPublicMethod() &amp;&amp; target(bean) &amp;&amp; @annotation(auditable)", value="com.xyz.lib.Pointcuts.anyPublicMethod() &amp;&amp; target(bean) &amp;&amp; @annotation(auditable)",
argNames="bean,auditable") argNames="bean,auditable")
public void audit(JoinPoint jp, Object bean, Auditable auditable) { public void audit(JoinPoint jp, Object bean, Auditable auditable) {
@ -1297,7 +1297,7 @@ public void audit(JoinPoint jp, Object bean, Auditable auditable) {
"argNames" attribute. For example, the following advice need not "argNames" attribute. For example, the following advice need not
declare the "argNames" attribute:</para> declare the "argNames" attribute:</para>
<programlisting>@Before( <programlisting language="java">@Before(
"com.xyz.lib.Pointcuts.anyPublicMethod()") "com.xyz.lib.Pointcuts.anyPublicMethod()")
public void audit(JoinPoint jp) { public void audit(JoinPoint jp) {
<lineannotation>// ... use jp</lineannotation> <lineannotation>// ... use jp</lineannotation>
@ -1355,7 +1355,7 @@ public void audit(JoinPoint jp) {
to ensure that the advice signature binds each of the method to ensure that the advice signature binds each of the method
parameters in order. For example:</para> parameters in order. For example:</para>
<programlisting>@Around("execution(List&lt;Account&gt; find*(..)) &amp;&amp;" + <programlisting language="java">@Around("execution(List&lt;Account&gt; find*(..)) &amp;&amp;" +
"com.xyz.myapp.SystemArchitecture.inDataAccessLayer() &amp;&amp; " + "com.xyz.myapp.SystemArchitecture.inDataAccessLayer() &amp;&amp; " +
"args(accountHolderNamePattern)") "args(accountHolderNamePattern)")
public Object preProcessQueryPattern(ProceedingJoinPoint pjp, String accountHolderNamePattern) public Object preProcessQueryPattern(ProceedingJoinPoint pjp, String accountHolderNamePattern)
@ -1423,7 +1423,7 @@ throws Throwable {
implement the <interfacename>UsageTracked</interfacename> interface. (In implement the <interfacename>UsageTracked</interfacename> interface. (In
order to expose statistics via JMX for example.)</para> order to expose statistics via JMX for example.)</para>
<programlisting>@Aspect <programlisting language="java">@Aspect
public class UsageTracking { public class UsageTracking {
@DeclareParents(value="com.xzy.myapp.service.*+", @DeclareParents(value="com.xzy.myapp.service.*+",
@ -1447,7 +1447,7 @@ public class UsageTracking {
<interfacename>UsageTracked</interfacename> interface. If accessing a <interfacename>UsageTracked</interfacename> interface. If accessing a
bean programmatically you would write the following:</para> bean programmatically you would write the following:</para>
<programlisting>UsageTracked usageTracked = (UsageTracked) context.getBean("myService");</programlisting> <programlisting language="java">UsageTracked usageTracked = (UsageTracked) context.getBean("myService");</programlisting>
</section> </section>
<section id="aop-instantiation-models"> <section id="aop-instantiation-models">
@ -1469,7 +1469,7 @@ public class UsageTracking {
<interfacename>@Aspect</interfacename> annotation. Let's look at an <interfacename>@Aspect</interfacename> annotation. Let's look at an
example, and then we'll explain how it works.</para> example, and then we'll explain how it works.</para>
<programlisting>@Aspect("perthis(com.xyz.myapp.SystemArchitecture.businessService())") <programlisting language="java">@Aspect("perthis(com.xyz.myapp.SystemArchitecture.businessService())")
public class MyAspect { public class MyAspect {
private int someState; private int someState;
@ -1519,7 +1519,7 @@ public class MyAspect {
advice so that we can call proceed multiple times. Here's how the basic advice so that we can call proceed multiple times. Here's how the basic
aspect implementation looks:</para> aspect implementation looks:</para>
<programlisting>@Aspect <programlisting language="java">@Aspect
public class ConcurrentOperationExecutor implements Ordered { public class ConcurrentOperationExecutor implements Ordered {
private static final int DEFAULT_MAX_RETRIES = 2; private static final int DEFAULT_MAX_RETRIES = 2;
@ -1573,7 +1573,7 @@ public class ConcurrentOperationExecutor implements Ordered {
<para>The corresponding Spring configuration is:</para> <para>The corresponding Spring configuration is:</para>
<programlisting>&lt;aop:aspectj-autoproxy/&gt; <programlisting language="xml">&lt;aop:aspectj-autoproxy/&gt;
&lt;bean id="concurrentOperationExecutor" &lt;bean id="concurrentOperationExecutor"
class="com.xyz.myapp.service.impl.ConcurrentOperationExecutor"&gt; class="com.xyz.myapp.service.impl.ConcurrentOperationExecutor"&gt;
@ -1585,7 +1585,7 @@ public class ConcurrentOperationExecutor implements Ordered {
operations, we might define an <interfacename>Idempotent</interfacename> operations, we might define an <interfacename>Idempotent</interfacename>
annotation:</para> annotation:</para>
<programlisting>@Retention(RetentionPolicy.RUNTIME) <programlisting language="java">@Retention(RetentionPolicy.RUNTIME)
public @interface Idempotent { public @interface Idempotent {
<lineannotation>// marker annotation</lineannotation> <lineannotation>// marker annotation</lineannotation>
}</programlisting> }</programlisting>
@ -1595,7 +1595,7 @@ public @interface Idempotent {
simply involves refining the pointcut expression so that only simply involves refining the pointcut expression so that only
<interfacename>@Idempotent</interfacename> operations match:</para> <interfacename>@Idempotent</interfacename> operations match:</para>
<programlisting>@Around("com.xyz.myapp.SystemArchitecture.businessService() &amp;&amp; " + <programlisting language="java">@Around("com.xyz.myapp.SystemArchitecture.businessService() &amp;&amp; " +
"@annotation(com.xyz.myapp.service.Idempotent)") "@annotation(com.xyz.myapp.service.Idempotent)")
public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable { public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
... ...
@ -1653,7 +1653,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
the backing bean is referenced using the <literal>ref</literal> the backing bean is referenced using the <literal>ref</literal>
attribute:</para> attribute:</para>
<programlisting>&lt;aop:config&gt; <programlisting language="xml">&lt;aop:config&gt;
&lt;aop:aspect id="myAspect" ref="aBean"&gt; &lt;aop:aspect id="myAspect" ref="aBean"&gt;
... ...
&lt;/aop:aspect&gt; &lt;/aop:aspect&gt;
@ -1678,7 +1678,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
<para>A pointcut representing the execution of any business service in <para>A pointcut representing the execution of any business service in
the service layer could be defined as follows:</para> the service layer could be defined as follows:</para>
<programlisting>&lt;aop:config&gt; <programlisting language="xml">&lt;aop:config&gt;
&lt;aop:pointcut id="businessService" &lt;aop:pointcut id="businessService"
expression="execution(* com.xyz.myapp.service.*.*(..))"/&gt; expression="execution(* com.xyz.myapp.service.*.*(..))"/&gt;
@ -1694,7 +1694,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
AspectJ reflection APIs). On JDK 1.5 therefore, another way of defining AspectJ reflection APIs). On JDK 1.5 therefore, another way of defining
the above pointcut would be:</para> the above pointcut would be:</para>
<programlisting>&lt;aop:config&gt; <programlisting language="xml">&lt;aop:config&gt;
&lt;aop:pointcut id="businessService" &lt;aop:pointcut id="businessService"
expression="com.xyz.myapp.SystemArchitecture.businessService()"/&gt; expression="com.xyz.myapp.SystemArchitecture.businessService()"/&gt;
@ -1707,7 +1707,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
<para>Declaring a pointcut inside an aspect is very similar to declaring <para>Declaring a pointcut inside an aspect is very similar to declaring
a top-level pointcut:</para> a top-level pointcut:</para>
<programlisting>&lt;aop:config&gt; <programlisting language="xml">&lt;aop:config&gt;
&lt;aop:aspect id="myAspect" ref="aBean"&gt; &lt;aop:aspect id="myAspect" ref="aBean"&gt;
@ -1725,7 +1725,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
example, the following pointcut collects the 'this' object as the join example, the following pointcut collects the 'this' object as the join
point context and passes it to advice:</para> point context and passes it to advice:</para>
<programlisting>&lt;aop:config&gt; <programlisting language="xml">&lt;aop:config&gt;
&lt;aop:aspect id="myAspect" ref="aBean"&gt; &lt;aop:aspect id="myAspect" ref="aBean"&gt;
@ -1741,7 +1741,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
<para>The advice must be declared to receive the collected join point <para>The advice must be declared to receive the collected join point
context by including parameters of the matching names:</para> context by including parameters of the matching names:</para>
<programlisting>public void monitor(Object service) { <programlisting language="java">public void monitor(Object service) {
... ...
}</programlisting> }</programlisting>
@ -1750,7 +1750,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
used in place of '&amp;&amp;', '||' and '!' respectively. For example, used in place of '&amp;&amp;', '||' and '!' respectively. For example,
the previous pointcut may be better written as:</para> the previous pointcut may be better written as:</para>
<programlisting>&lt;aop:config&gt; <programlisting language="xml">&lt;aop:config&gt;
&lt;aop:aspect id="myAspect" ref="aBean"&gt; &lt;aop:aspect id="myAspect" ref="aBean"&gt;
@ -1784,7 +1784,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
declared inside an <literal>&lt;aop:aspect&gt;</literal> using the declared inside an <literal>&lt;aop:aspect&gt;</literal> using the
&lt;aop:before&gt; element.</para> &lt;aop:before&gt; element.</para>
<programlisting>&lt;aop:aspect id="beforeExample" ref="aBean"&gt; <programlisting language="xml">&lt;aop:aspect id="beforeExample" ref="aBean"&gt;
&lt;aop:before &lt;aop:before
pointcut-ref="dataAccessOperation" pointcut-ref="dataAccessOperation"
@ -1800,7 +1800,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
<literal>pointcut-ref</literal> attribute with a <literal>pointcut-ref</literal> attribute with a
<literal>pointcut</literal> attribute:</para> <literal>pointcut</literal> attribute:</para>
<programlisting>&lt;aop:aspect id="beforeExample" ref="aBean"&gt; <programlisting language="xml">&lt;aop:aspect id="beforeExample" ref="aBean"&gt;
&lt;aop:before &lt;aop:before
pointcut="execution(* com.xyz.myapp.dao.*.*(..))" pointcut="execution(* com.xyz.myapp.dao.*.*(..))"
@ -1831,7 +1831,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
<literal>&lt;aop:aspect&gt;</literal> in the same way as before <literal>&lt;aop:aspect&gt;</literal> in the same way as before
advice. For example:</para> advice. For example:</para>
<programlisting>&lt;aop:aspect id="afterReturningExample" ref="aBean"&gt; <programlisting language="xml">&lt;aop:aspect id="afterReturningExample" ref="aBean"&gt;
&lt;aop:after-returning &lt;aop:after-returning
pointcut-ref="dataAccessOperation" pointcut-ref="dataAccessOperation"
@ -1846,7 +1846,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
specify the name of the parameter to which the return value should be specify the name of the parameter to which the return value should be
passed:</para> passed:</para>
<programlisting>&lt;aop:aspect id="afterReturningExample" ref="aBean"&gt; <programlisting language="xml">&lt;aop:aspect id="afterReturningExample" ref="aBean"&gt;
&lt;aop:after-returning &lt;aop:after-returning
pointcut-ref="dataAccessOperation" pointcut-ref="dataAccessOperation"
@ -1862,7 +1862,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
matching in the same way as described for @AfterReturning. For matching in the same way as described for @AfterReturning. For
example, the method signature may be declared as:</para> example, the method signature may be declared as:</para>
<programlisting>public void doAccessCheck(Object retVal) {...</programlisting> <programlisting language="java">public void doAccessCheck(Object retVal) {...</programlisting>
</section> </section>
<section id="aop-schema-advice-after-throwing"> <section id="aop-schema-advice-after-throwing">
@ -1873,7 +1873,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
<literal>&lt;aop:aspect&gt;</literal> using the after-throwing <literal>&lt;aop:aspect&gt;</literal> using the after-throwing
element:</para> element:</para>
<programlisting>&lt;aop:aspect id="afterThrowingExample" ref="aBean"&gt; <programlisting language="xml">&lt;aop:aspect id="afterThrowingExample" ref="aBean"&gt;
&lt;aop:after-throwing &lt;aop:after-throwing
pointcut-ref="dataAccessOperation" pointcut-ref="dataAccessOperation"
@ -1888,7 +1888,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
specify the name of the parameter to which the exception should be specify the name of the parameter to which the exception should be
passed:</para> passed:</para>
<programlisting>&lt;aop:aspect id="afterThrowingExample" ref="aBean"&gt; <programlisting language="xml">&lt;aop:aspect id="afterThrowingExample" ref="aBean"&gt;
&lt;aop:after-throwing &lt;aop:after-throwing
pointcut-ref="dataAccessOperation" pointcut-ref="dataAccessOperation"
@ -1904,7 +1904,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
matching in the same way as described for @AfterThrowing. For example, matching in the same way as described for @AfterThrowing. For example,
the method signature may be declared as:</para> the method signature may be declared as:</para>
<programlisting>public void doRecoveryActions(DataAccessException dataAccessEx) {...</programlisting> <programlisting language="java">public void doRecoveryActions(DataAccessException dataAccessEx) {...</programlisting>
</section> </section>
<section id="aop-schema-advice-after-finally"> <section id="aop-schema-advice-after-finally">
@ -1914,7 +1914,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
exits. It is declared using the <literal>after</literal> exits. It is declared using the <literal>after</literal>
element:</para> element:</para>
<programlisting>&lt;aop:aspect id="afterFinallyExample" ref="aBean"&gt; <programlisting language="xml">&lt;aop:aspect id="afterFinallyExample" ref="aBean"&gt;
&lt;aop:after &lt;aop:after
pointcut-ref="dataAccessOperation" pointcut-ref="dataAccessOperation"
@ -1951,7 +1951,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
linkend="aop-ataspectj-around-advice" /> for notes on calling proceed linkend="aop-ataspectj-around-advice" /> for notes on calling proceed
with an <classname>Object[]</classname>.</para> with an <classname>Object[]</classname>.</para>
<programlisting>&lt;aop:aspect id="aroundExample" ref="aBean"&gt; <programlisting language="xml">&lt;aop:aspect id="aroundExample" ref="aBean"&gt;
&lt;aop:around &lt;aop:around
pointcut-ref="businessService" pointcut-ref="businessService"
@ -1965,7 +1965,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
advice would be exactly the same as in the @AspectJ example (minus the advice would be exactly the same as in the @AspectJ example (minus the
annotation of course):</para> annotation of course):</para>
<programlisting>public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable { <programlisting language="java">public Object doBasicProfiling(ProceedingJoinPoint pjp) throws Throwable {
<lineannotation>// start stopwatch</lineannotation> <lineannotation>// start stopwatch</lineannotation>
Object retVal = pjp.proceed(); Object retVal = pjp.proceed();
<lineannotation>// stop stopwatch</lineannotation> <lineannotation>// stop stopwatch</lineannotation>
@ -1987,7 +1987,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
attribute in an advice annotation as described in <xref attribute in an advice annotation as described in <xref
linkend="aop-ataspectj-advice-params-names" />. For example:</para> linkend="aop-ataspectj-advice-params-names" />. For example:</para>
<programlisting>&lt;aop:before <programlisting language="xml">&lt;aop:before
pointcut="com.xyz.lib.Pointcuts.anyPublicMethod() and @annotation(auditable)" pointcut="com.xyz.lib.Pointcuts.anyPublicMethod() and @annotation(auditable)"
method="audit" method="audit"
arg-names="auditable"/&gt;</programlisting> arg-names="auditable"/&gt;</programlisting>
@ -1999,7 +1999,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
approach that illustrates some around advice used in conjunction with approach that illustrates some around advice used in conjunction with
a number of strongly typed parameters.</para> a number of strongly typed parameters.</para>
<programlisting>package x.y.service; <programlisting language="java">package x.y.service;
public interface FooService { public interface FooService {
@ -2021,7 +2021,7 @@ public class DefaultFooService implements FooService {
<methodname>profile(..)</methodname> is to be used as <methodname>profile(..)</methodname> is to be used as
<literal>around</literal> advice:</para> <literal>around</literal> advice:</para>
<programlisting>package x.y; <programlisting language="java">package x.y;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.util.StopWatch; import org.springframework.util.StopWatch;
@ -2045,7 +2045,7 @@ public class SimpleProfiler {
effect the execution of the above advice for a particular join effect the execution of the above advice for a particular join
point:</para> point:</para>
<programlisting>&lt;beans xmlns="http://www.springframework.org/schema/beans" <programlisting language="xml">&lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation=" xsi:schemaLocation="
@ -2076,7 +2076,7 @@ http://www.springframework.org/schema/aop http://www.springframework.org/schema/
<para>If we had the following driver script, we would get output <para>If we had the following driver script, we would get output
something like this on standard output:</para> something like this on standard output:</para>
<programlisting>import org.springframework.beans.factory.BeanFactory; <programlisting language="java">import org.springframework.beans.factory.BeanFactory;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
import x.y.service.FooService; import x.y.service.FooService;
@ -2128,7 +2128,7 @@ ms % Task name
<interfacename>UsageTracked</interfacename> interface. (In order to <interfacename>UsageTracked</interfacename> interface. (In order to
expose statistics via JMX for example.)</para> expose statistics via JMX for example.)</para>
<programlisting>&lt;aop:aspect id="usageTrackerAspect" ref="usageTracking"&gt; <programlisting language="xml">&lt;aop:aspect id="usageTrackerAspect" ref="usageTracking"&gt;
&lt;aop:declare-parents &lt;aop:declare-parents
types-matching="com.xzy.myapp.service.*+" types-matching="com.xzy.myapp.service.*+"
@ -2145,7 +2145,7 @@ ms % Task name
<para>The class backing the <literal>usageTracking</literal> bean would <para>The class backing the <literal>usageTracking</literal> bean would
contain the method:</para> contain the method:</para>
<programlisting>public void recordUsage(UsageTracked usageTracked) { <programlisting language="java">public void recordUsage(UsageTracked usageTracked) {
usageTracked.incrementUseCount(); usageTracked.incrementUseCount();
}</programlisting> }</programlisting>
@ -2159,7 +2159,7 @@ ms % Task name
interface. If accessing a bean programmatically you would write the interface. If accessing a bean programmatically you would write the
following:</para> following:</para>
<programlisting>UsageTracked usageTracked = (UsageTracked) context.getBean("myService");</programlisting> <programlisting language="java">UsageTracked usageTracked = (UsageTracked) context.getBean("myService");</programlisting>
</section> </section>
<section id="aop-schema-instatiation-models"> <section id="aop-schema-instatiation-models">
@ -2186,7 +2186,7 @@ ms % Task name
see it used in conjunction with transactional advice, which also has its see it used in conjunction with transactional advice, which also has its
own namespace support in Spring 2.0. Here's how it looks:</para> own namespace support in Spring 2.0. Here's how it looks:</para>
<programlisting>&lt;aop:config&gt; <programlisting language="xml">&lt;aop:config&gt;
&lt;aop:pointcut id="businessService" &lt;aop:pointcut id="businessService"
expression="execution(* com.xyz.myapp.service.*.*(..))"/&gt; expression="execution(* com.xyz.myapp.service.*.*(..))"/&gt;
@ -2235,7 +2235,7 @@ ms % Task name
aspect implementation looks (it's just a regular Java class using the aspect implementation looks (it's just a regular Java class using the
schema support):</para> schema support):</para>
<programlisting>public class ConcurrentOperationExecutor implements Ordered { <programlisting language="java">public class ConcurrentOperationExecutor implements Ordered {
private static final int DEFAULT_MAX_RETRIES = 2; private static final int DEFAULT_MAX_RETRIES = 2;
@ -2288,7 +2288,7 @@ ms % Task name
<para>The corresponding Spring configuration is:</para> <para>The corresponding Spring configuration is:</para>
<programlisting>&lt;aop:config&gt; <programlisting language="xml">&lt;aop:config&gt;
&lt;aop:aspect id="concurrentOperationRetry" ref="concurrentOperationExecutor"&gt; &lt;aop:aspect id="concurrentOperationRetry" ref="concurrentOperationExecutor"&gt;
@ -2315,7 +2315,7 @@ ms % Task name
introducing an <interfacename>Idempotent</interfacename> introducing an <interfacename>Idempotent</interfacename>
annotation:</para> annotation:</para>
<programlisting>@Retention(RetentionPolicy.RUNTIME) <programlisting language="java">@Retention(RetentionPolicy.RUNTIME)
public @interface Idempotent { public @interface Idempotent {
<lineannotation>// marker annotation</lineannotation> <lineannotation>// marker annotation</lineannotation>
}</programlisting> }</programlisting>
@ -2325,7 +2325,7 @@ public @interface Idempotent {
simply involves refining the pointcut expression so that only simply involves refining the pointcut expression so that only
<interfacename>@Idempotent</interfacename> operations match:</para> <interfacename>@Idempotent</interfacename> operations match:</para>
<programlisting> &lt;aop:pointcut id="idempotentOperation" <programlisting language="xml"> &lt;aop:pointcut id="idempotentOperation"
expression="execution(* com.xyz.myapp.service.*.*(..)) and expression="execution(* com.xyz.myapp.service.*.*(..)) and
@annotation(com.xyz.myapp.service.Idempotent)"/&gt;</programlisting> @annotation(com.xyz.myapp.service.Idempotent)"/&gt;</programlisting>
</section> </section>
@ -2401,7 +2401,7 @@ public @interface Idempotent {
in XML. For example, in the @AspectJ style you can write something in XML. For example, in the @AspectJ style you can write something
like:</para> like:</para>
<programlisting> @Pointcut(execution(* get*())) <programlisting language="java"> @Pointcut(execution(* get*()))
public void propertyAccess() {} public void propertyAccess() {}
@Pointcut(execution(org.xyz.Account+ *(..)) @Pointcut(execution(org.xyz.Account+ *(..))
@ -2412,7 +2412,7 @@ public @interface Idempotent {
<para>In the XML style I can declare the first two pointcuts:</para> <para>In the XML style I can declare the first two pointcuts:</para>
<programlisting> &lt;aop:pointcut id="propertyAccess" <programlisting language="xml"> &lt;aop:pointcut id="propertyAccess"
expression="execution(* get*())"/&gt; expression="execution(* get*())"/&gt;
&lt;aop:pointcut id="operationReturningAnAccount" &lt;aop:pointcut id="operationReturningAnAccount"
@ -2492,7 +2492,7 @@ public @interface Idempotent {
the value of the <literal>proxy-target-class</literal> attribute of the the value of the <literal>proxy-target-class</literal> attribute of the
<literal>&lt;aop:config&gt;</literal> element to true:</para> <literal>&lt;aop:config&gt;</literal> element to true:</para>
<programlisting>&lt;aop:config <emphasis role="bold">proxy-target-class="true"</emphasis>&gt; <programlisting language="xml">&lt;aop:config <emphasis role="bold">proxy-target-class="true"</emphasis>&gt;
<lineannotation>&lt;!-- other beans defined here... --&gt;</lineannotation> <lineannotation>&lt;!-- other beans defined here... --&gt;</lineannotation>
&lt;/aop:config&gt;</programlisting> &lt;/aop:config&gt;</programlisting>
@ -2501,7 +2501,7 @@ public @interface Idempotent {
<literal>&lt;aop:aspectj-autoproxy&gt;</literal> element to <literal>&lt;aop:aspectj-autoproxy&gt;</literal> element to
<literal>true</literal>:</para> <literal>true</literal>:</para>
<programlisting>&lt;aop:aspectj-autoproxy <emphasis role="bold">proxy-target-class="true"</emphasis>/&gt;</programlisting> <programlisting language="xml">&lt;aop:aspectj-autoproxy <emphasis role="bold">proxy-target-class="true"</emphasis>/&gt;</programlisting>
<note> <note>
<para>Multiple <literal>&lt;aop:config/&gt;</literal> sections are <para>Multiple <literal>&lt;aop:config/&gt;</literal> sections are
@ -2531,7 +2531,7 @@ public @interface Idempotent {
un-proxied, nothing-special-about-it, straight object reference, as un-proxied, nothing-special-about-it, straight object reference, as
illustrated by the following code snippet.</para> illustrated by the following code snippet.</para>
<programlisting>public class SimplePojo implements Pojo { <programlisting language="java">public class SimplePojo implements Pojo {
public void foo() { public void foo() {
<lineannotation>// this next method invocation is a <emphasis <lineannotation>// this next method invocation is a <emphasis
@ -2562,7 +2562,7 @@ public @interface Idempotent {
</imageobject> </imageobject>
</mediaobject></para> </mediaobject></para>
<programlisting>public class Main { <programlisting language="java">public class Main {
public static void main(String[] args) { public static void main(String[] args) {
@ -2588,7 +2588,7 @@ public @interface Idempotent {
</imageobject> </imageobject>
</mediaobject></para> </mediaobject></para>
<programlisting>public class Main { <programlisting language="java">public class Main {
public static void main(String[] args) { public static void main(String[] args) {
@ -2628,7 +2628,7 @@ public @interface Idempotent {
out precisely because it is so horrendous. You can (choke!) totally tie out precisely because it is so horrendous. You can (choke!) totally tie
the logic within your class to Spring AOP by doing this:</para> the logic within your class to Spring AOP by doing this:</para>
<programlisting>public class SimplePojo implements Pojo { <programlisting language="java">public class SimplePojo implements Pojo {
public void foo() { public void foo() {
<lineannotation>// this works, but... gah!</lineannotation> <lineannotation>// this works, but... gah!</lineannotation>
@ -2646,7 +2646,7 @@ public @interface Idempotent {
It also requires some additional configuration when the proxy is being It also requires some additional configuration when the proxy is being
created:</para> created:</para>
<programlisting>public class Main { <programlisting language="java">public class Main {
public static void main(String[] args) { public static void main(String[] args) {
@ -2685,7 +2685,7 @@ public @interface Idempotent {
or more @AspectJ aspects. Basic usage for this class is very simple, as or more @AspectJ aspects. Basic usage for this class is very simple, as
illustrated below. See the Javadocs for full information.</para> illustrated below. See the Javadocs for full information.</para>
<programlisting><lineannotation>// create a factory that can generate a proxy for the given target object</lineannotation> <programlisting language="java"><lineannotation>// create a factory that can generate a proxy for the given target object</lineannotation>
AspectJProxyFactory factory = new AspectJProxyFactory(targetObject); AspectJProxyFactory factory = new AspectJProxyFactory(targetObject);
<lineannotation>// add an aspect, the class must be an @AspectJ aspect <lineannotation>// add an aspect, the class must be an @AspectJ aspect
@ -2739,7 +2739,7 @@ MyInterfaceType proxy = factory.getProxy();</programlisting>
a class as eligible for Spring-driven configuration. In the simplest a class as eligible for Spring-driven configuration. In the simplest
case it can be used just as a marker annotation:</para> case it can be used just as a marker annotation:</para>
<programlisting>package com.xyz.myapp.domain; <programlisting language="java">package com.xyz.myapp.domain;
import org.springframework.beans.factory.annotation.Configurable; import org.springframework.beans.factory.annotation.Configurable;
@ -2757,14 +2757,14 @@ public class Account {
way to declare the prototype definition is simply to omit the way to declare the prototype definition is simply to omit the
<literal>id</literal> attribute:</para> <literal>id</literal> attribute:</para>
<programlisting>&lt;bean class="com.xyz.myapp.domain.Account" scope="prototype"&gt; <programlisting language="xml">&lt;bean class="com.xyz.myapp.domain.Account" scope="prototype"&gt;
&lt;property name="fundsTransferService" ref="fundsTransferService"/&gt; &lt;property name="fundsTransferService" ref="fundsTransferService"/&gt;
&lt;/bean&gt;</programlisting> &lt;/bean&gt;</programlisting>
<para>If you want to explicitly specify the name of the prototype bean <para>If you want to explicitly specify the name of the prototype bean
definition to use, you can do so directly in the annotation:</para> definition to use, you can do so directly in the annotation:</para>
<programlisting>package com.xyz.myapp.domain; <programlisting language="java">package com.xyz.myapp.domain;
import org.springframework.beans.factory.annotation.Configurable; import org.springframework.beans.factory.annotation.Configurable;
@ -2827,7 +2827,7 @@ public class Account {
<interfacename>@Configurable</interfacename> declaration like <interfacename>@Configurable</interfacename> declaration like
so:</para> so:</para>
<programlisting>@Configurable(preConstruction=true)</programlisting> <programlisting language="java">@Configurable(preConstruction=true)</programlisting>
<para>You can find out more information about the language semantics <para>You can find out more information about the language semantics
of the various pointcut types in AspectJ <ulink of the various pointcut types in AspectJ <ulink
@ -2850,12 +2850,12 @@ public class Account {
namespace</link> defines a convenient tag for doing this: just include namespace</link> defines a convenient tag for doing this: just include
the following in your application context configuration:</para> the following in your application context configuration:</para>
<programlisting>&lt;context:spring-configured/&gt;</programlisting> <programlisting language="xml">&lt;context:spring-configured/&gt;</programlisting>
<para>If you are using the DTD instead of schema, the equivalent <para>If you are using the DTD instead of schema, the equivalent
definition is:</para> definition is:</para>
<programlisting>&lt;bean <programlisting language="xml">&lt;bean
class="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect" class="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"
factory-method="aspectOf"/&gt;</programlisting> factory-method="aspectOf"/&gt;</programlisting>
@ -2868,7 +2868,7 @@ public class Account {
manually specify that the bean depends on the configuration manually specify that the bean depends on the configuration
aspect.</para> aspect.</para>
<programlisting>&lt;bean id="myService" <programlisting language="xml">&lt;bean id="myService"
class="com.xzy.myapp.service.MyService" class="com.xzy.myapp.service.MyService"
depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"&gt; depends-on="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"&gt;
@ -2982,7 +2982,7 @@ public class Account {
domain model using prototype bean definitions that match the domain model using prototype bean definitions that match the
fully-qualified class names:</para> fully-qualified class names:</para>
<programlisting>public aspect DomainObjectConfiguration extends AbstractBeanConfigurerAspect { <programlisting language="java">public aspect DomainObjectConfiguration extends AbstractBeanConfigurerAspect {
public DomainObjectConfiguration() { public DomainObjectConfiguration() {
setBeanWiringInfoResolver(new ClassNameBeanWiringInfoResolver()); setBeanWiringInfoResolver(new ClassNameBeanWiringInfoResolver());
@ -3014,7 +3014,7 @@ public class Account {
ensures that Spring obtains the aspect instance by asking AspectJ for it ensures that Spring obtains the aspect instance by asking AspectJ for it
rather than trying to create an instance itself. For example:</para> rather than trying to create an instance itself. For example:</para>
<programlisting>&lt;bean id="profiler" class="com.xyz.profiler.Profiler" <programlisting language="xml">&lt;bean id="profiler" class="com.xyz.profiler.Profiler"
<emphasis role="bold">factory-method="aspectOf"</emphasis>&gt; <emphasis role="bold">factory-method="aspectOf"</emphasis>&gt;
&lt;property name="profilingStrategy" ref="jamonProfilingStrategy"/&gt; &lt;property name="profilingStrategy" ref="jamonProfilingStrategy"/&gt;
&lt;/bean&gt;</programlisting> &lt;/bean&gt;</programlisting>
@ -3039,7 +3039,7 @@ public class Account {
and only beans with names matched by at least one of the patterns will and only beans with names matched by at least one of the patterns will
be used for Spring AOP autoproxy configuration:</para> be used for Spring AOP autoproxy configuration:</para>
<programlisting>&lt;aop:aspectj-autoproxy&gt; <programlisting language="xml">&lt;aop:aspectj-autoproxy&gt;
&lt;aop:include name="thisBean"/&gt; &lt;aop:include name="thisBean"/&gt;
&lt;aop:include name="thatBean"/&gt; &lt;aop:include name="thatBean"/&gt;
&lt;/aop:aspectj-autoproxy&gt;</programlisting> &lt;/aop:aspectj-autoproxy&gt;</programlisting>
@ -3108,7 +3108,7 @@ public class Account {
quick-and-dirty time-based profiler, using the @AspectJ-style of quick-and-dirty time-based profiler, using the @AspectJ-style of
aspect declaration.</para> aspect declaration.</para>
<programlisting>package foo; <programlisting language="java">package foo;
import org.aspectj.lang.ProceedingJoinPoint; import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect; import org.aspectj.lang.annotation.Aspect;
@ -3145,7 +3145,7 @@ public class ProfilingAspect {
classpath called ' <filename>META-INF/aop.xml</filename>' is standard classpath called ' <filename>META-INF/aop.xml</filename>' is standard
AspectJ.</para> AspectJ.</para>
<programlisting>&lt;!DOCTYPE aspectj PUBLIC <programlisting language="xml">&lt;!DOCTYPE aspectj PUBLIC
"-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"&gt; "-//AspectJ//DTD//EN" "http://www.eclipse.org/aspectj/dtd/aspectj.dtd"&gt;
&lt;aspectj&gt; &lt;aspectj&gt;
@ -3175,7 +3175,7 @@ public class ProfilingAspect {
are some more options that you can specify, but these are detailed are some more options that you can specify, but these are detailed
later).</para> later).</para>
<programlisting>&lt;?xml version="1.0" encoding="UTF-8"?&gt; <programlisting language="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans" &lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:context="http://www.springframework.org/schema/context"
@ -3198,7 +3198,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/sch
<methodname>main(..)</methodname> method to demonstrate the LTW in <methodname>main(..)</methodname> method to demonstrate the LTW in
action.</para> action.</para>
<programlisting>package foo; <programlisting language="java">package foo;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
@ -3256,7 +3256,7 @@ ms % Task name
on the <classname>Main</classname> program will yield the same on the <classname>Main</classname> program will yield the same
result.</para> result.</para>
<programlisting>package foo; <programlisting language="java">package foo;
import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext;
@ -3400,7 +3400,7 @@ public final class Main {
below a valid <literal>&lt;context:load-time-weaver/&gt;</literal> below a valid <literal>&lt;context:load-time-weaver/&gt;</literal>
definition that uses default settings.</para> definition that uses default settings.</para>
<programlisting>&lt;?xml version="1.0" encoding="UTF-8"?&gt; <programlisting language="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans" &lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:context="http://www.springframework.org/schema/context"
@ -3493,7 +3493,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/sch
<literal>&lt;context:load-time-weaver/&gt;</literal> element. Find <literal>&lt;context:load-time-weaver/&gt;</literal> element. Find
below an example of doing just that:</para> below an example of doing just that:</para>
<programlisting>&lt;?xml version="1.0" encoding="UTF-8"?&gt; <programlisting language="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans" &lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:context="http://www.springframework.org/schema/context" xmlns:context="http://www.springframework.org/schema/context"
@ -3601,7 +3601,7 @@ http://www.springframework.org/schema/context http://www.springframework.org/sch
included in Tomcat's common lib directory in order to make this included in Tomcat's common lib directory in order to make this
setup work.</para> setup work.</para>
<programlisting>&lt;Context path="/myWebApp" docBase="/my/webApp/location"&gt; <programlisting language="xml">&lt;Context path="/myWebApp" docBase="/my/webApp/location"&gt;
&lt;Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader" &lt;Loader loaderClass="org.springframework.instrument.classloading.tomcat.TomcatInstrumentableClassLoader"
useSystemClassLoaderAsParent="false"/&gt; useSystemClassLoaderAsParent="false"/&gt;
&lt;/Context&gt; &lt;/Context&gt;

File diff suppressed because it is too large Load Diff

View File

@ -27,7 +27,7 @@
to be a more capable interface for abstracting access to low-level to be a more capable interface for abstracting access to low-level
resources.</para> resources.</para>
<programlisting><![CDATA[public interface Resource extends InputStreamSource { <programlisting language="java"><![CDATA[public interface Resource extends InputStreamSource {
boolean exists(); boolean exists();
@ -44,7 +44,7 @@
String getDescription(); String getDescription();
}]]></programlisting> }]]></programlisting>
<programlisting><![CDATA[public interface InputStreamSource { <programlisting language="java"><![CDATA[public interface InputStreamSource {
InputStream getInputStream() throws IOException; InputStream getInputStream() throws IOException;
}]]></programlisting> }]]></programlisting>
@ -244,7 +244,7 @@
to be implemented by objects that can return (i.e. load) to be implemented by objects that can return (i.e. load)
<interfacename>Resource</interfacename> instances.</para> <interfacename>Resource</interfacename> instances.</para>
<programlisting>public interface ResourceLoader { <programlisting language="java">public interface ResourceLoader {
Resource getResource(String location); Resource getResource(String location);
}</programlisting> }</programlisting>
@ -261,7 +261,7 @@
of code was executed against a of code was executed against a
<classname>ClassPathXmlApplicationContext</classname> instance:</para> <classname>ClassPathXmlApplicationContext</classname> instance:</para>
<programlisting>Resource template = ctx.getResource("some/resource/path/myTemplate.txt);</programlisting> <programlisting language="java">Resource template = ctx.getResource("some/resource/path/myTemplate.txt);</programlisting>
<para>What would be returned would be a <para>What would be returned would be a
<classname>ClassPathResource</classname>; if the same method was executed <classname>ClassPathResource</classname>; if the same method was executed
@ -278,15 +278,15 @@
application context type, by specifying the special application context type, by specifying the special
<literal>classpath:</literal> prefix:</para> <literal>classpath:</literal> prefix:</para>
<programlisting>Resource template = ctx.getResource("classpath:some/resource/path/myTemplate.txt);</programlisting> <programlisting language="java">Resource template = ctx.getResource("classpath:some/resource/path/myTemplate.txt);</programlisting>
<para>Similarly, one can force a <classname>UrlResource</classname> to be <para>Similarly, one can force a <classname>UrlResource</classname> to be
used by specifying any of the standard <classname>java.net.URL</classname> used by specifying any of the standard <classname>java.net.URL</classname>
prefixes:</para> prefixes:</para>
<programlisting>Resource template = ctx.getResource("file:/some/resource/path/myTemplate.txt);</programlisting> <programlisting language="java">Resource template = ctx.getResource("file:/some/resource/path/myTemplate.txt);</programlisting>
<programlisting>Resource template = ctx.getResource("http://myhost.com/resource/path/myTemplate.txt);</programlisting> <programlisting language="java">Resource template = ctx.getResource("http://myhost.com/resource/path/myTemplate.txt);</programlisting>
<para>The following table summarizes the strategy for converting <para>The following table summarizes the strategy for converting
<classname>String</classname>s to <classname>String</classname>s to
@ -361,7 +361,7 @@
a special marker interface, identifying objects that expect to be provided a special marker interface, identifying objects that expect to be provided
with a <interfacename>ResourceLoader</interfacename> reference.</para> with a <interfacename>ResourceLoader</interfacename> reference.</para>
<programlisting><![CDATA[public interface ResourceLoaderAware { <programlisting language="java"><![CDATA[public interface ResourceLoaderAware {
void setResourceLoader(ResourceLoader resourceLoader); void setResourceLoader(ResourceLoader resourceLoader);
}]]></programlisting> }]]></programlisting>
@ -427,7 +427,7 @@
<interfacename>Resource</interfacename>, it can be configured with a <interfacename>Resource</interfacename>, it can be configured with a
simple string for that resource, as follows:</para> simple string for that resource, as follows:</para>
<programlisting><![CDATA[<bean id="myBean" class="..."> <programlisting language="xml"><![CDATA[<bean id="myBean" class="...">
<property name="template" value="some/resource/path/myTemplate.txt"/> <property name="template" value="some/resource/path/myTemplate.txt"/>
</bean>]]></programlisting> </bean>]]></programlisting>
@ -446,9 +446,9 @@
<classname>UrlResource</classname> (the latter being used to access a <classname>UrlResource</classname> (the latter being used to access a
filesystem file).</para> filesystem file).</para>
<programlisting><![CDATA[<property name="template" value="classpath:some/resource/path/myTemplate.txt">]]></programlisting> <programlisting language="xml"><![CDATA[<property name="template" value="classpath:some/resource/path/myTemplate.txt">]]></programlisting>
<programlisting><![CDATA[<property name="template" value="file:/some/resource/path/myTemplate.txt"/>]]></programlisting> <programlisting language="xml"><![CDATA[<property name="template" value="file:/some/resource/path/myTemplate.txt"/>]]></programlisting>
</section> </section>
<section id="resources-app-ctx"> <section id="resources-app-ctx">
@ -468,7 +468,7 @@
specific application context. For example, if you create a specific application context. For example, if you create a
<classname>ClassPathXmlApplicationContext</classname> as follows:</para> <classname>ClassPathXmlApplicationContext</classname> as follows:</para>
<programlisting><![CDATA[ApplicationContext ctx = new ClassPathXmlApplicationContext("conf/appContext.xml");]]></programlisting> <programlisting language="java"><![CDATA[ApplicationContext ctx = new ClassPathXmlApplicationContext("conf/appContext.xml");]]></programlisting>
<para>The bean definitions will be loaded from the classpath, as a <para>The bean definitions will be loaded from the classpath, as a
<classname></classname><classname>ClassPathResource</classname> will be <classname></classname><classname>ClassPathResource</classname> will be
@ -476,7 +476,7 @@
<classname>FileSystemXmlApplicationContext</classname> as <classname>FileSystemXmlApplicationContext</classname> as
follows:</para> follows:</para>
<programlisting><![CDATA[ApplicationContext ctx = <programlisting language="java"><![CDATA[ApplicationContext ctx =
new FileSystemXmlApplicationContext("conf/appContext.xml");]]></programlisting> new FileSystemXmlApplicationContext("conf/appContext.xml");]]></programlisting>
<para>The bean definition will be loaded from a filesystem location, in <para>The bean definition will be loaded from a filesystem location, in
@ -487,7 +487,7 @@
<interfacename>Resource</interfacename> created to load the definition. <interfacename>Resource</interfacename> created to load the definition.
So this <classname>FileSystemXmlApplicationContext</classname>...</para> So this <classname>FileSystemXmlApplicationContext</classname>...</para>
<programlisting><![CDATA[ApplicationContext ctx = <programlisting language="java"><![CDATA[ApplicationContext ctx =
new FileSystemXmlApplicationContext("classpath:conf/appContext.xml");]]></programlisting> new FileSystemXmlApplicationContext("classpath:conf/appContext.xml");]]></programlisting>
<para>... will actually load its bean definitions from the classpath. <para>... will actually load its bean definitions from the classpath.
@ -521,7 +521,7 @@
and <literal>'daos.xml'</literal> could be instantiated like and <literal>'daos.xml'</literal> could be instantiated like
so...</para> so...</para>
<programlisting><![CDATA[ApplicationContext ctx = new ClassPathXmlApplicationContext( <programlisting language="java"><![CDATA[ApplicationContext ctx = new ClassPathXmlApplicationContext(
new String[] {"services.xml", "daos.xml"}, MessengerService.class);]]></programlisting> new String[] {"services.xml", "daos.xml"}, MessengerService.class);]]></programlisting>
<para>Please do consult the Javadocs for the <para>Please do consult the Javadocs for the
@ -617,7 +617,7 @@
string may use the special <literal>classpath*:</literal> string may use the special <literal>classpath*:</literal>
prefix:</para> prefix:</para>
<programlisting><![CDATA[ApplicationContext ctx = <programlisting language="java"><![CDATA[ApplicationContext ctx =
new ClassPathXmlApplicationContext("classpath*:conf/appContext.xml");]]></programlisting> new ClassPathXmlApplicationContext("classpath*:conf/appContext.xml");]]></programlisting>
<para>This special prefix specifies that all classpath resources that <para>This special prefix specifies that all classpath resources that
@ -706,19 +706,19 @@
all location paths as relative, whether they start with a leading slash all location paths as relative, whether they start with a leading slash
or not. In practice, this means the following are equivalent:</para> or not. In practice, this means the following are equivalent:</para>
<programlisting><![CDATA[ApplicationContext ctx = <programlisting language="java"><![CDATA[ApplicationContext ctx =
new FileSystemXmlApplicationContext("conf/context.xml");]]></programlisting> new FileSystemXmlApplicationContext("conf/context.xml");]]></programlisting>
<programlisting><![CDATA[ApplicationContext ctx = <programlisting language="java"><![CDATA[ApplicationContext ctx =
new FileSystemXmlApplicationContext("/conf/context.xml");]]></programlisting> new FileSystemXmlApplicationContext("/conf/context.xml");]]></programlisting>
<para>As are the following: (Even though it would make sense for them to <para>As are the following: (Even though it would make sense for them to
be different, as one case is relative and the other absolute.)</para> be different, as one case is relative and the other absolute.)</para>
<programlisting><![CDATA[FileSystemXmlApplicationContext ctx = ...; <programlisting language="java"><![CDATA[FileSystemXmlApplicationContext ctx = ...;
ctx.getResource("some/resource/path/myTemplate.txt");]]></programlisting> ctx.getResource("some/resource/path/myTemplate.txt");]]></programlisting>
<programlisting><![CDATA[FileSystemXmlApplicationContext ctx = ...; <programlisting language="java"><![CDATA[FileSystemXmlApplicationContext ctx = ...;
ctx.getResource("/some/resource/path/myTemplate.txt");]]></programlisting> ctx.getResource("/some/resource/path/myTemplate.txt");]]></programlisting>
<para>In practice, if true absolute filesystem paths are needed, it is <para>In practice, if true absolute filesystem paths are needed, it is
@ -728,10 +728,10 @@ ctx.getResource("/some/resource/path/myTemplate.txt");]]></programlisting>
the use of a <classname>UrlResource</classname>, by using the the use of a <classname>UrlResource</classname>, by using the
<literal>file:</literal> URL prefix.</para> <literal>file:</literal> URL prefix.</para>
<programlisting><lineannotation>// actual context type doesn't matter, the <interfacename>Resource</interfacename> will always be <classname>UrlResource</classname></lineannotation><![CDATA[ <programlisting language="java"><lineannotation>// actual context type doesn't matter, the <interfacename>Resource</interfacename> will always be <classname>UrlResource</classname></lineannotation><![CDATA[
ctx.getResource("file:/some/resource/path/myTemplate.txt");]]></programlisting> ctx.getResource("file:/some/resource/path/myTemplate.txt");]]></programlisting>
<programlisting><lineannotation>// force this FileSystemXmlApplicationContext to load its definition via a <classname>UrlResource</classname></lineannotation><![CDATA[ <programlisting language="java"><lineannotation>// force this FileSystemXmlApplicationContext to load its definition via a <classname>UrlResource</classname></lineannotation><![CDATA[
ApplicationContext ctx = ApplicationContext ctx =
new FileSystemXmlApplicationContext("file:/conf/context.xml");]]></programlisting> new FileSystemXmlApplicationContext("file:/conf/context.xml");]]></programlisting>
</section> </section>

View File

@ -468,7 +468,7 @@
the test will be enabled. This annotation can be applied to an the test will be enabled. This annotation can be applied to an
entire class or individual methods.</para> entire class or individual methods.</para>
<programlisting>@IfProfileValue(name="java.vendor", value="Sun Microsystems Inc.") <programlisting language="java">@IfProfileValue(name="java.vendor", value="Sun Microsystems Inc.")
public void testProcessWhichRunsOnlyOnSunJvm() { public void testProcessWhichRunsOnlyOnSunJvm() {
<lineannotation>// some logic that should run only on Java VMs from Sun Microsystems</lineannotation> <lineannotation>// some logic that should run only on Java VMs from Sun Microsystems</lineannotation>
}</programlisting> }</programlisting>
@ -479,7 +479,7 @@ public void testProcessWhichRunsOnlyOnSunJvm() {
for <emphasis>test groups</emphasis> in a JUnit environment. for <emphasis>test groups</emphasis> in a JUnit environment.
Consider the following example:</para> Consider the following example:</para>
<programlisting>@IfProfileValue(name="test-groups", values={"unit-tests", "integration-tests"}) <programlisting language="java">@IfProfileValue(name="test-groups", values={"unit-tests", "integration-tests"})
public void testProcessWhichRunsForUnitOrIntegrationTestGroups() { public void testProcessWhichRunsForUnitOrIntegrationTestGroups() {
<lineannotation>// some logic that should run only for unit and integration test groups</lineannotation> <lineannotation>// some logic that should run only for unit and integration test groups</lineannotation>
}</programlisting> }</programlisting>
@ -498,7 +498,7 @@ public void testProcessWhichRunsForUnitOrIntegrationTestGroups() {
<classname>SystemProfileValueSource</classname> will be used by <classname>SystemProfileValueSource</classname> will be used by
default.</para> default.</para>
<programlisting>@ProfileValueSourceConfiguration(CustomProfileValueSource.class) <programlisting language="java">@ProfileValueSourceConfiguration(CustomProfileValueSource.class)
public class CustomProfileValueSourceTests { public class CustomProfileValueSourceTests {
<lineannotation>// class body...</lineannotation> <lineannotation>// class body...</lineannotation>
}</programlisting> }</programlisting>
@ -514,7 +514,7 @@ public class CustomProfileValueSourceTests {
test method finishes execution (regardless of whether the test test method finishes execution (regardless of whether the test
passed or not).</para> passed or not).</para>
<programlisting>@DirtiesContext <programlisting language="java">@DirtiesContext
public void testProcessWhichDirtiesAppCtx() { public void testProcessWhichDirtiesAppCtx() {
<lineannotation>// some logic that results in the Spring container being dirtied</lineannotation> <lineannotation>// some logic that results in the Spring container being dirtied</lineannotation>
}</programlisting> }</programlisting>
@ -531,7 +531,7 @@ public void testProcessWhichDirtiesAppCtx() {
Likewise if an instance of the exception is <emphasis>not</emphasis> Likewise if an instance of the exception is <emphasis>not</emphasis>
thrown during the test method execution then the test fails.</para> thrown during the test method execution then the test fails.</para>
<programlisting>@ExpectedException(SomeBusinessException.class) <programlisting language="java">@ExpectedException(SomeBusinessException.class)
public void testProcessRainyDayScenario() { public void testProcessRainyDayScenario() {
<lineannotation>// some logic that should result in an <classname>Exception</classname> being thrown</lineannotation> <lineannotation>// some logic that should result in an <classname>Exception</classname> being thrown</lineannotation>
}</programlisting> }</programlisting>
@ -552,7 +552,7 @@ public void testProcessRainyDayScenario() {
<emphasis>set up</emphasis> or <emphasis>tear down</emphasis> of the <emphasis>set up</emphasis> or <emphasis>tear down</emphasis> of the
test fixture.</para> test fixture.</para>
<programlisting>@Timed(millis=1000) <programlisting language="java">@Timed(millis=1000)
public void testProcessWithOneSecondTimeout() { public void testProcessWithOneSecondTimeout() {
<lineannotation>// some logic that should not take longer than 1 second to execute</lineannotation> <lineannotation>// some logic that should not take longer than 1 second to execute</lineannotation>
}</programlisting> }</programlisting>
@ -571,7 +571,7 @@ public void testProcessWithOneSecondTimeout() {
up</emphasis> or <emphasis>tear down</emphasis> of the test up</emphasis> or <emphasis>tear down</emphasis> of the test
fixture.</para> fixture.</para>
<programlisting>@Repeat(10) <programlisting language="java">@Repeat(10)
public void testProcessRepeatedly() { public void testProcessRepeatedly() {
<lineannotation>// ...</lineannotation> <lineannotation>// ...</lineannotation>
}</programlisting> }</programlisting>
@ -588,7 +588,7 @@ public void testProcessRepeatedly() {
committed. Use <interfacename>@Rollback</interfacename> to override committed. Use <interfacename>@Rollback</interfacename> to override
the default rollback flag configured at the class level.</para> the default rollback flag configured at the class level.</para>
<programlisting>@Rollback(false) <programlisting language="java">@Rollback(false)
public void testProcessWithoutRollback() { public void testProcessWithoutRollback() {
<lineannotation>// ...</lineannotation> <lineannotation>// ...</lineannotation>
}</programlisting> }</programlisting>
@ -602,7 +602,7 @@ public void testProcessWithoutRollback() {
test method must <emphasis>not</emphasis> execute in a transactional test method must <emphasis>not</emphasis> execute in a transactional
context.</para> context.</para>
<programlisting>@NotTransactional <programlisting language="java">@NotTransactional
public void testProcessWithoutTransaction() { public void testProcessWithoutTransaction() {
<lineannotation>// ...</lineannotation> <lineannotation>// ...</lineannotation>
}</programlisting> }</programlisting>
@ -659,7 +659,7 @@ public void testProcessWithoutTransaction() {
and exposes a <literal>protected</literal> method that subclasses can and exposes a <literal>protected</literal> method that subclasses can
override to provide the location of context definition files:</para> override to provide the location of context definition files:</para>
<programlisting>protected String[] getConfigLocations()</programlisting> <programlisting language="java">protected String[] getConfigLocations()</programlisting>
<para>Implementations of this method must provide an array containing <para>Implementations of this method must provide an array containing
the resource locations of XML configuration metadata - typically on the resource locations of XML configuration metadata - typically on
@ -669,9 +669,9 @@ public void testProcessWithoutTransaction() {
configuration. As an alternative you may choose to override one of the configuration. As an alternative you may choose to override one of the
following. See the respective JavaDoc for further details.</para> following. See the respective JavaDoc for further details.</para>
<programlisting>protected String[] getConfigPaths()</programlisting> <programlisting language="java">protected String[] getConfigPaths()</programlisting>
<programlisting>protected String getConfigPath()</programlisting> <programlisting language="java">protected String getConfigPath()</programlisting>
<para>By default, once loaded, the configuration file set will be <para>By default, once loaded, the configuration file set will be
reused for each test case. Thus the setup cost will be incurred only reused for each test case. Thus the setup cost will be incurred only
@ -710,7 +710,7 @@ public void testProcessWithoutTransaction() {
at a JUnit 3.8 based implementation of the test class itself (we will at a JUnit 3.8 based implementation of the test class itself (we will
look at the configuration immediately afterwards).</para> look at the configuration immediately afterwards).</para>
<programlisting>public final class HibernateTitleDaoTests <emphasis <programlisting language="java">public final class HibernateTitleDaoTests <emphasis
role="bold">extends AbstractDependencyInjectionSpringContextTests</emphasis> { role="bold">extends AbstractDependencyInjectionSpringContextTests</emphasis> {
<lineannotation>// this instance will be (automatically) dependency injected</lineannotation> <lineannotation>// this instance will be (automatically) dependency injected</lineannotation>
@ -738,7 +738,7 @@ public void testProcessWithoutTransaction() {
<literal>"classpath:com/foo/daos.xml"</literal>) looks like <literal>"classpath:com/foo/daos.xml"</literal>) looks like
this:</para> this:</para>
<programlisting>&lt;?xml version="1.0" encoding="UTF-8"?&gt; <programlisting language="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans" &lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans xsi:schemaLocation="http://www.springframework.org/schema/beans
@ -785,7 +785,7 @@ public void testProcessWithoutTransaction() {
configuration does not need to change, merely the test configuration does not need to change, merely the test
fixture).</para> fixture).</para>
<programlisting>public final class HibernateTitleDaoTests <emphasis <programlisting language="java">public final class HibernateTitleDaoTests <emphasis
role="bold">extends AbstractDependencyInjectionSpringContextTests</emphasis> { role="bold">extends AbstractDependencyInjectionSpringContextTests</emphasis> {
public HibernateTitleDaoTests() { public HibernateTitleDaoTests() {
@ -1096,7 +1096,7 @@ public void testProcessWithoutTransaction() {
application context from application context from
<literal>"classpath:/com/example/MyTest-context.xml"</literal>.</para> <literal>"classpath:/com/example/MyTest-context.xml"</literal>.</para>
<programlisting>package com.example; <programlisting language="java">package com.example;
@RunWith(SpringJUnit4ClassRunner.class) @RunWith(SpringJUnit4ClassRunner.class)
<lineannotation>// ApplicationContext will be loaded from <literal>"classpath:/com/example/MyTest-context.xml"</literal></lineannotation> <lineannotation>// ApplicationContext will be loaded from <literal>"classpath:/com/example/MyTest-context.xml"</literal></lineannotation>
@ -1118,7 +1118,7 @@ public class MyTest {
configure your own custom configure your own custom
<interfacename>ContextLoader</interfacename>.</para> <interfacename>ContextLoader</interfacename>.</para>
<programlisting>@RunWith(SpringJUnit4ClassRunner.class) <programlisting language="java">@RunWith(SpringJUnit4ClassRunner.class)
<lineannotation>// ApplicationContext will be loaded from <literal>"/applicationContext.xml"</literal> and <literal>"/applicationContext-test.xml"</literal></lineannotation> <lineannotation>// ApplicationContext will be loaded from <literal>"/applicationContext.xml"</literal> and <literal>"/applicationContext-test.xml"</literal></lineannotation>
<lineannotation>// in the root of the classpath</lineannotation> <lineannotation>// in the root of the classpath</lineannotation>
<emphasis role="bold">@ContextConfiguration(locations={"/applicationContext.xml", "/applicationContext-test.xml"})</emphasis> <emphasis role="bold">@ContextConfiguration(locations={"/applicationContext.xml", "/applicationContext-test.xml"})</emphasis>
@ -1144,7 +1144,7 @@ public class MyTest {
"/extended-context.xml" may therefore override those defined in "/extended-context.xml" may therefore override those defined in
"/base-context.xml".</para> "/base-context.xml".</para>
<programlisting>@RunWith(SpringJUnit4ClassRunner.class) <programlisting language="java">@RunWith(SpringJUnit4ClassRunner.class)
<lineannotation>// ApplicationContext will be loaded from <literal>"/base-context.xml"</literal> in the root of the classpath</lineannotation> <lineannotation>// ApplicationContext will be loaded from <literal>"/base-context.xml"</literal> in the root of the classpath</lineannotation>
<emphasis role="bold">@ContextConfiguration(locations={"/base-context.xml"})</emphasis> <emphasis role="bold">@ContextConfiguration(locations={"/base-context.xml"})</emphasis>
public class BaseTest { public class BaseTest {
@ -1245,7 +1245,7 @@ public class ExtendedTest extends BaseTest {
JUnit 4.4. The same DI techniques can be used in conjunction with any JUnit 4.4. The same DI techniques can be used in conjunction with any
testing framework.</emphasis></para> testing framework.</emphasis></para>
<programlisting>@RunWith(SpringJUnit4ClassRunner.class) <programlisting language="java">@RunWith(SpringJUnit4ClassRunner.class)
<lineannotation>// specifies the Spring configuration to load for this test fixture</lineannotation> <lineannotation>// specifies the Spring configuration to load for this test fixture</lineannotation>
<emphasis role="bold">@ContextConfiguration(locations={"daos.xml"})</emphasis> <emphasis role="bold">@ContextConfiguration(locations={"daos.xml"})</emphasis>
public final class HibernateTitleDaoTests { public final class HibernateTitleDaoTests {
@ -1266,7 +1266,7 @@ public final class HibernateTitleDaoTests {
<para>Alternatively, we can configure the class to use <para>Alternatively, we can configure the class to use
<interfacename>@Autowired</interfacename> for setter injection.</para> <interfacename>@Autowired</interfacename> for setter injection.</para>
<programlisting>@RunWith(SpringJUnit4ClassRunner.class) <programlisting language="java">@RunWith(SpringJUnit4ClassRunner.class)
<lineannotation>// specifies the Spring configuration to load for this test fixture</lineannotation> <lineannotation>// specifies the Spring configuration to load for this test fixture</lineannotation>
<emphasis role="bold">@ContextConfiguration(locations={"daos.xml"})</emphasis> <emphasis role="bold">@ContextConfiguration(locations={"daos.xml"})</emphasis>
public final class HibernateTitleDaoTests { public final class HibernateTitleDaoTests {
@ -1291,7 +1291,7 @@ public final class HibernateTitleDaoTests {
<para>Now let's take a look at an example using <para>Now let's take a look at an example using
<interfacename>@Resource</interfacename> for field injection.</para> <interfacename>@Resource</interfacename> for field injection.</para>
<programlisting>@RunWith(SpringJUnit4ClassRunner.class) <programlisting language="java">@RunWith(SpringJUnit4ClassRunner.class)
<lineannotation>// specifies the Spring configuration to load for this test fixture</lineannotation> <lineannotation>// specifies the Spring configuration to load for this test fixture</lineannotation>
<emphasis role="bold">@ContextConfiguration(locations={"daos.xml"})</emphasis> <emphasis role="bold">@ContextConfiguration(locations={"daos.xml"})</emphasis>
public final class HibernateTitleDaoTests { public final class HibernateTitleDaoTests {
@ -1312,7 +1312,7 @@ public final class HibernateTitleDaoTests {
<para>Finally, here is an example using <para>Finally, here is an example using
<interfacename>@Resource</interfacename> for setter injection.</para> <interfacename>@Resource</interfacename> for setter injection.</para>
<programlisting>@RunWith(SpringJUnit4ClassRunner.class) <programlisting language="java">@RunWith(SpringJUnit4ClassRunner.class)
<lineannotation>// specifies the Spring configuration to load for this test fixture</lineannotation> <lineannotation>// specifies the Spring configuration to load for this test fixture</lineannotation>
<emphasis role="bold">@ContextConfiguration(locations={"daos.xml"})</emphasis> <emphasis role="bold">@ContextConfiguration(locations={"daos.xml"})</emphasis>
public final class HibernateTitleDaoTests { public final class HibernateTitleDaoTests {
@ -1338,7 +1338,7 @@ public final class HibernateTitleDaoTests {
by the <interfacename>@ContextConfiguration</interfacename> annotation by the <interfacename>@ContextConfiguration</interfacename> annotation
(i.e., <literal>"daos.xml"</literal>) which looks like this:</para> (i.e., <literal>"daos.xml"</literal>) which looks like this:</para>
<programlisting>&lt;?xml version="1.0" encoding="UTF-8"?&gt; <programlisting language="xml">&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;beans xmlns="http://www.springframework.org/schema/beans" &lt;beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans xsi:schemaLocation="http://www.springframework.org/schema/beans
@ -1364,7 +1364,7 @@ public final class HibernateTitleDaoTests {
you may override the setter and use the <interfacename>@Qualifier</interfacename> you may override the setter and use the <interfacename>@Qualifier</interfacename>
annotation to indicate a specific target bean as follows:</para> annotation to indicate a specific target bean as follows:</para>
<programlisting>... <programlisting language="java">...
@Override @Autowired @Override @Autowired
public void setDataSource(<emphasis role="bold">@Qualifier("myDataSource")</emphasis> DataSource dataSource) { public void setDataSource(<emphasis role="bold">@Qualifier("myDataSource")</emphasis> DataSource dataSource) {
super.setDataSource(dataSource); super.setDataSource(dataSource);
@ -1389,7 +1389,7 @@ public final class HibernateTitleDaoTests {
Note that this always points to a bean with that specific name, Note that this always points to a bean with that specific name,
no matter whether there is one or more beans of the given type.</para> no matter whether there is one or more beans of the given type.</para>
<programlisting>... <programlisting language="java">...
@Override <emphasis role="bold">@Resource("myDataSource")</emphasis> @Override <emphasis role="bold">@Resource("myDataSource")</emphasis>
public void setDataSource(DataSource dataSource) { public void setDataSource(DataSource dataSource) {
super.setDataSource(dataSource); super.setDataSource(dataSource);
@ -1479,7 +1479,7 @@ public final class HibernateTitleDaoTests {
support</link> section of the reference manual for further information support</link> section of the reference manual for further information
and configuration examples.</para> and configuration examples.</para>
<programlisting>@RunWith(SpringJUnit4ClassRunner.class) <programlisting language="java">@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration @ContextConfiguration
<emphasis role="bold">@TransactionConfiguration(transactionManager="txMgr", defaultRollback=false)</emphasis> <emphasis role="bold">@TransactionConfiguration(transactionManager="txMgr", defaultRollback=false)</emphasis>
<emphasis role="bold">@Transactional</emphasis> <emphasis role="bold">@Transactional</emphasis>
@ -1695,7 +1695,7 @@ public class FictitiousTransactionalTest {
<interfacename>ApplicationContext</interfacename> be configured via <interfacename>ApplicationContext</interfacename> be configured via
<interfacename>@ContextConfiguration</interfacename>.</emphasis></para> <interfacename>@ContextConfiguration</interfacename>.</emphasis></para>
<programlisting>@RunWith(SpringJUnit4ClassRunner.class) <programlisting language="java">@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({}) @TestExecutionListeners({})
public class SimpleTest { public class SimpleTest {
@ -1913,7 +1913,7 @@ public class SimpleTest {
<interfacename>ContextLoader</interfacename> strategy to use for <interfacename>ContextLoader</interfacename> strategy to use for
loading the context.</para> loading the context.</para>
<programlisting>@ContextConfiguration(locations={"example/test-context.xml"}, loader=CustomContextLoader.class) <programlisting language="java">@ContextConfiguration(locations={"example/test-context.xml"}, loader=CustomContextLoader.class)
public class CustomConfiguredApplicationContextTests { public class CustomConfiguredApplicationContextTests {
<lineannotation>// class body...</lineannotation> <lineannotation>// class body...</lineannotation>
}</programlisting> }</programlisting>
@ -1937,7 +1937,7 @@ public class CustomConfiguredApplicationContextTests {
will be used in conjunction with will be used in conjunction with
<interfacename>@ContextConfiguration</interfacename>.</para> <interfacename>@ContextConfiguration</interfacename>.</para>
<programlisting>@ContextConfiguration <programlisting language="java">@ContextConfiguration
@TestExecutionListeners({CustomTestExecutionListener.class, AnotherTestExecutionListener.class}) @TestExecutionListeners({CustomTestExecutionListener.class, AnotherTestExecutionListener.class})
public class CustomTestExecutionListenerTests { public class CustomTestExecutionListenerTests {
<lineannotation>// class body...</lineannotation> <lineannotation>// class body...</lineannotation>
@ -1965,7 +1965,7 @@ public class CustomTestExecutionListenerTests {
used in conjunction with used in conjunction with
<interfacename>@ContextConfiguration</interfacename>.</para> <interfacename>@ContextConfiguration</interfacename>.</para>
<programlisting>@ContextConfiguration <programlisting language="java">@ContextConfiguration
@TransactionConfiguration(transactionManager="txMgr", defaultRollback=false) @TransactionConfiguration(transactionManager="txMgr", defaultRollback=false)
public class CustomConfiguredTransactionalTests { public class CustomConfiguredTransactionalTests {
<lineannotation>// class body...</lineannotation> <lineannotation>// class body...</lineannotation>
@ -1982,7 +1982,7 @@ public class CustomConfiguredTransactionalTests {
transaction via the <interfacename>@Transactional</interfacename> transaction via the <interfacename>@Transactional</interfacename>
annotation.</para> annotation.</para>
<programlisting>@BeforeTransaction <programlisting language="java">@BeforeTransaction
public void beforeTransaction() { public void beforeTransaction() {
<lineannotation>// logic to be executed before a transaction is started</lineannotation> <lineannotation>// logic to be executed before a transaction is started</lineannotation>
}</programlisting> }</programlisting>
@ -1998,7 +1998,7 @@ public void beforeTransaction() {
transaction via the <interfacename>@Transactional</interfacename> transaction via the <interfacename>@Transactional</interfacename>
annotation.</para> annotation.</para>
<programlisting>@AfterTransaction <programlisting language="java">@AfterTransaction
public void afterTransaction() { public void afterTransaction() {
<lineannotation>// logic to be executed after a transaction has ended</lineannotation> <lineannotation>// logic to be executed after a transaction has ended</lineannotation>
}</programlisting> }</programlisting>
@ -2019,7 +2019,7 @@ public void afterTransaction() {
<classname>AbstractClinicTests</classname>, for which a partial listing <classname>AbstractClinicTests</classname>, for which a partial listing
is shown below:</para> is shown below:</para>
<programlisting><emphasis role="bold">@ContextConfiguration</emphasis> <programlisting language="java"><emphasis role="bold">@ContextConfiguration</emphasis>
public abstract class AbstractClinicTests <emphasis role="bold">extends AbstractTransactionalJUnit4SpringContextTests</emphasis> { public abstract class AbstractClinicTests <emphasis role="bold">extends AbstractTransactionalJUnit4SpringContextTests</emphasis> {
<emphasis role="bold">@Autowired</emphasis> <emphasis role="bold">@Autowired</emphasis>
@ -2106,7 +2106,7 @@ public abstract class AbstractClinicTests <emphasis role="bold">extends Abstract
overriding beans defined in overriding beans defined in
<literal>"AbstractClinicTests-context.xml"</literal>.</para> <literal>"AbstractClinicTests-context.xml"</literal>.</para>
<programlisting><emphasis role="bold">@ContextConfiguration</emphasis> <programlisting language="java"><emphasis role="bold">@ContextConfiguration</emphasis>
public class HibernateClinicTests extends AbstractClinicTests { } public class HibernateClinicTests extends AbstractClinicTests { }
</programlisting> </programlisting>

View File

@ -43,7 +43,7 @@
an <interfacename>Errors</interfacename> object so that while validating, validators can report an <interfacename>Errors</interfacename> object so that while validating, validators can report
validation failures to the <interfacename>Errors</interfacename> object.</para> validation failures to the <interfacename>Errors</interfacename> object.</para>
<para>Let's consider a small data object:</para> <para>Let's consider a small data object:</para>
<programlisting><![CDATA[ <programlisting language="java"><![CDATA[
public class Person { public class Person {
private String name; private String name;
@ -71,7 +71,7 @@ public class Person {
Implementing a <interfacename>Validator</interfacename> is fairly straightforward, Implementing a <interfacename>Validator</interfacename> is fairly straightforward,
especially when you know of the <classname>ValidationUtils</classname> helper class especially when you know of the <classname>ValidationUtils</classname> helper class
that the Spring Framework also provides.</para> that the Spring Framework also provides.</para>
<programlisting><![CDATA[public class PersonValidator implements Validator { <programlisting language="java"><![CDATA[public class PersonValidator implements Validator {
]]><lineannotation>/** ]]><lineannotation>/**
* This <interfacename>Validator</interfacename> validates <emphasis role="bold">just</emphasis> <classname>Person</classname> instances * This <interfacename>Validator</interfacename> validates <emphasis role="bold">just</emphasis> <classname>Person</classname> instances
@ -109,7 +109,7 @@ public class Person {
<classname>AddressValidator</classname> class without recourse to copy-n-paste you can <classname>AddressValidator</classname> class without recourse to copy-n-paste you can
dependency-inject or instantiate an <classname>AddressValidator</classname> within your dependency-inject or instantiate an <classname>AddressValidator</classname> within your
<classname>CustomerValidator</classname>, and use it like so:</para> <classname>CustomerValidator</classname>, and use it like so:</para>
<programlisting><![CDATA[public class CustomerValidator implements Validator { <programlisting language="java"><![CDATA[public class CustomerValidator implements Validator {
private final Validator addressValidator; private final Validator addressValidator;
@ -285,7 +285,7 @@ public class Person {
<interfacename>PropertyEditors</interfacename>.)</emphasis></para> <interfacename>PropertyEditors</interfacename>.)</emphasis></para>
<para>Consider the following two classes:</para> <para>Consider the following two classes:</para>
<programlisting><![CDATA[public class Company { <programlisting language="java"><![CDATA[public class Company {
private String name; private String name;
private Employee managingDirector; private Employee managingDirector;
@ -303,7 +303,7 @@ public class Person {
} }
}]]></programlisting> }]]></programlisting>
<programlisting><![CDATA[public class Employee { <programlisting language="java"><![CDATA[public class Employee {
private String name; private String name;
private float salary; private float salary;
@ -324,7 +324,7 @@ public class Person {
<para>The following code snippets show some examples of how to retrieve <para>The following code snippets show some examples of how to retrieve
and manipulate some of the properties of instantiated and manipulate some of the properties of instantiated
<literal>Companies</literal> and <literal>Employees</literal>:</para> <literal>Companies</literal> and <literal>Employees</literal>:</para>
<programlisting><![CDATA[BeanWrapper company = BeanWrapperImpl(new Company()); <programlisting language="java"><![CDATA[BeanWrapper company = BeanWrapperImpl(new Company());
]]><lineannotation>// setting the company name..</lineannotation><![CDATA[ ]]><lineannotation>// setting the company name..</lineannotation><![CDATA[
company.setPropertyValue("name", "Some Company Inc."); company.setPropertyValue("name", "Some Company Inc.");
]]><lineannotation>// ... can also be done like this:</lineannotation><![CDATA[ ]]><lineannotation>// ... can also be done like this:</lineannotation><![CDATA[
@ -547,7 +547,7 @@ Float salary = (Float) company.getPropertyValue("managingDirector.salary");]]></
would associate a <classname>CustomNumberEditor</classname> with the <literal>age</literal> would associate a <classname>CustomNumberEditor</classname> with the <literal>age</literal>
property of the <classname>Foo</classname> class. property of the <classname>Foo</classname> class.
</para> </para>
<programlisting><![CDATA[public class FooBeanInfo extends SimpleBeanInfo { <programlisting language="java"><![CDATA[public class FooBeanInfo extends SimpleBeanInfo {
public PropertyDescriptor[] getPropertyDescriptors() { public PropertyDescriptor[] getPropertyDescriptors() {
try { try {
@ -602,7 +602,7 @@ Float salary = (Float) company.getPropertyValue("managingDirector.salary");]]></
<para>Consider a user class <classname>ExoticType</classname>, and another class <para>Consider a user class <classname>ExoticType</classname>, and another class
<classname>DependsOnExoticType</classname> which needs <classname>ExoticType</classname> set as a property:</para> <classname>DependsOnExoticType</classname> which needs <classname>ExoticType</classname> set as a property:</para>
<programlisting><![CDATA[package example; <programlisting language="java"><![CDATA[package example;
public class ExoticType { public class ExoticType {
@ -624,11 +624,11 @@ public class DependsOnExoticType {
<para>When things are properly set up, we want to be able to assign the type property as a string, which a <para>When things are properly set up, we want to be able to assign the type property as a string, which a
<interfacename>PropertyEditor</interfacename> will behind the scenes convert into an actual <interfacename>PropertyEditor</interfacename> will behind the scenes convert into an actual
<classname>ExoticType</classname> instance:</para> <classname>ExoticType</classname> instance:</para>
<programlisting><![CDATA[<bean id="sample" class="example.DependsOnExoticType"> <programlisting language="xml"><![CDATA[<bean id="sample" class="example.DependsOnExoticType">
<property name="type" value="aNameForExoticType"/> <property name="type" value="aNameForExoticType"/>
</bean>]]></programlisting> </bean>]]></programlisting>
<para>The <interfacename>PropertyEditor</interfacename> implementation could look similar to this:</para> <para>The <interfacename>PropertyEditor</interfacename> implementation could look similar to this:</para>
<programlisting><lineannotation>// converts string representation to <classname>ExoticType</classname> object</lineannotation><![CDATA[ <programlisting language="java"><lineannotation>// converts string representation to <classname>ExoticType</classname> object</lineannotation><![CDATA[
package example; package example;
public class ExoticTypeEditor extends PropertyEditorSupport { public class ExoticTypeEditor extends PropertyEditorSupport {
@ -650,7 +650,7 @@ public class ExoticTypeEditor extends PropertyEditorSupport {
<para>Finally, we use <classname>CustomEditorConfigurer</classname> to register the new <para>Finally, we use <classname>CustomEditorConfigurer</classname> to register the new
<interfacename>PropertyEditor</interfacename> with the <interfacename>ApplicationContext</interfacename>, <interfacename>PropertyEditor</interfacename> with the <interfacename>ApplicationContext</interfacename>,
which will then be able to use it as needed:</para> which will then be able to use it as needed:</para>
<programlisting><![CDATA[<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer"> <programlisting language="xml"><![CDATA[<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="customEditors"> <property name="customEditors">
<map> <map>
<entry key="example.ExoticType"> <entry key="example.ExoticType">
@ -684,7 +684,7 @@ public class ExoticTypeEditor extends PropertyEditorSupport {
example. First off, you need to create your own <interfacename>PropertyEditorRegistrar</interfacename> example. First off, you need to create your own <interfacename>PropertyEditorRegistrar</interfacename>
implementation:</para> implementation:</para>
<programlisting><![CDATA[package com.foo.editors.spring; <programlisting language="java"><![CDATA[package com.foo.editors.spring;
public final class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar { public final class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
@ -702,7 +702,7 @@ public final class CustomPropertyEditorRegistrar implements PropertyEditorRegist
of each property editor.</para> of each property editor.</para>
<para>Next we configure a <classname>CustomEditorConfigurer</classname> and inject an <para>Next we configure a <classname>CustomEditorConfigurer</classname> and inject an
instance of our <classname>CustomPropertyEditorRegistrar</classname> into it:</para> instance of our <classname>CustomPropertyEditorRegistrar</classname> into it:</para>
<programlisting><![CDATA[<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer"> <programlisting language="xml"><![CDATA[<bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
<property name="propertyEditorRegistrars"> <property name="propertyEditorRegistrars">
<list> <list>
<ref bean="customPropertyEditorRegistrar"/> <ref bean="customPropertyEditorRegistrar"/>
@ -719,7 +719,7 @@ public final class CustomPropertyEditorRegistrar implements PropertyEditorRegist
<interfacename>PropertyEditorRegistrar</interfacename> in the implementation of an <methodname>initBinder(..)</methodname> <interfacename>PropertyEditorRegistrar</interfacename> in the implementation of an <methodname>initBinder(..)</methodname>
method:</para> method:</para>
<programlisting><![CDATA[public final class RegisterUserController extends SimpleFormController { <programlisting language="java"><![CDATA[public final class RegisterUserController extends SimpleFormController {
private final PropertyEditorRegistrar customPropertyEditorRegistrar; private final PropertyEditorRegistrar customPropertyEditorRegistrar;