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
and methods. The complete interface is shown below:</para>
<programlisting><![CDATA[public interface Pointcut {
<programlisting language="java"><![CDATA[public interface Pointcut {
ClassFilter getClassFilter();
@ -51,7 +51,7 @@
<literal>matches()</literal> method always returns true, all target
classes will be matched:</para>
<programlisting><![CDATA[public interface ClassFilter {
<programlisting language="java"><![CDATA[public interface ClassFilter {
boolean matches(Class clazz);
}]]></programlisting>
@ -59,7 +59,7 @@
<para>The <interfacename>MethodMatcher</interfacename> interface is normally more
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);
@ -170,7 +170,7 @@
<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;
&lt;property name="patterns"&gt;
&lt;list&gt;
@ -189,7 +189,7 @@
as the one bean encapsulates both pointcut and advice, as shown
below:</para>
<para><programlisting>&lt;bean id="settersAndAbsquatulateAdvisor"
<para><programlisting language="xml">&lt;bean id="settersAndAbsquatulateAdvisor"
class="org.springframework.aop.support.RegexpMethodPointcutAdvisor"&gt;
&lt;property name="advice"&gt;
&lt;ref local="beanNameOfAopAllianceInterceptor"/&gt;
@ -260,7 +260,7 @@
just one abstract method (although it's possible to override other
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) {
// return true if custom criteria match
@ -332,7 +332,7 @@
advice using method interception. MethodInterceptors implementing
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;
}</programlisting>
@ -346,7 +346,7 @@
<para>A simple <classname>MethodInterceptor</classname> implementation
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 {
System.out.println("Before: invocation=[" + invocation + "]");
@ -393,7 +393,7 @@
although the usual objects apply to field interception and it's
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;
}</programlisting>
@ -410,7 +410,7 @@
<para>An example of a before advice in Spring, which counts all method
invocations:</para>
<programlisting>public class CountingBeforeAdvice implements MethodBeforeAdvice {
<programlisting language="java">public class CountingBeforeAdvice implements MethodBeforeAdvice {
private int count;
@ -437,7 +437,7 @@
given object implements one or more typed throws advice methods. These
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
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>
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 {
]]><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
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) {
]]><lineannotation>// Do something with all arguments</lineannotation><![CDATA[
@ -472,7 +472,7 @@
<literal>ServletException</literal>. Any number of throws advice
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 {
// Do something with remote exception
@ -501,7 +501,7 @@
<emphasis>org.springframework.aop.AfterReturningAdvice</emphasis>
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)
throws Throwable;
@ -514,7 +514,7 @@
<para>The following after returning advice counts all successful
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;
@ -543,7 +543,7 @@
and an <literal>IntroductionInterceptor</literal>, implementing the
following interface:</para>
<programlisting>public interface IntroductionInterceptor extends MethodInterceptor {
<programlisting language="java">public interface IntroductionInterceptor extends MethodInterceptor {
boolean implementsInterface(Class intf);
}</programlisting>
@ -563,7 +563,7 @@
<programlisting>public interface IntroductionAdvisor extends Advisor, IntroductionInfo {
<programlisting language="java">public interface IntroductionAdvisor extends Advisor, IntroductionInfo {
ClassFilter getClassFilter();
@ -603,7 +603,7 @@ public interface IntroductionInfo {
<para>
<programlisting>public interface Lockable {
<programlisting language="java">public interface Lockable {
void lock();
void unlock();
boolean locked();
@ -672,7 +672,7 @@ public interface IntroductionInfo {
<para>
<programlisting>public class LockMixin extends DelegatingIntroductionInterceptor
<programlisting language="java">public class LockMixin extends DelegatingIntroductionInterceptor
implements Lockable {
private boolean locked;
@ -722,7 +722,7 @@ public interface IntroductionInfo {
<para>
<programlisting>public class LockMixinAdvisor extends DefaultIntroductionAdvisor {
<programlisting language="java">public class LockMixinAdvisor extends DefaultIntroductionAdvisor {
public LockMixinAdvisor() {
super(new LockMixin(), Lockable.class);
@ -1032,7 +1032,7 @@ public interface IntroductionInfo {
</listitem>
</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="age"&gt;&lt;value&gt;51&lt;/value&gt;&lt;/property&gt;
&lt;/bean&gt;
@ -1076,12 +1076,12 @@ public interface IntroductionInfo {
<para>The "person" bean definition above can be used in place of a
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
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;/bean&gt;</programlisting></para>
@ -1097,7 +1097,7 @@ public interface IntroductionInfo {
<literal>ProxyFactoryBean</literal> definition is different; the advice
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;/bean&gt;
@ -1184,7 +1184,7 @@ public interface IntroductionInfo {
<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
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;property name="target" ref="service"/&gt;
&lt;property name="interceptorNames"&gt;
@ -1211,7 +1211,7 @@ public interface IntroductionInfo {
<para>First a parent, <emphasis>template</emphasis>, bean definition is
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;
&lt;property name="transactionManager" ref="transactionManager"/&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
definition, which wraps the target of the proxy as an inner bean
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;bean class="org.springframework.samples.MyServiceImpl"&gt;
&lt;/bean&gt;
@ -1234,7 +1234,7 @@ public interface IntroductionInfo {
<para>It is of course possible to override properties from the parent
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;bean class="org.springframework.samples.MySpecialServiceImpl"&gt;
&lt;/bean&gt;
@ -1273,7 +1273,7 @@ public interface IntroductionInfo {
with one interceptor and one advisor. The interfaces implemented by the
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.addAdvisor(myAdvisor);
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
implements. This interface includes the following methods:</para>
<programlisting>Advisor[] getAdvisors();
<programlisting language="java">Advisor[] getAdvisors();
void addAdvice(Advice advice) throws AopConfigException;
@ -1355,7 +1355,7 @@ boolean isFrozen();</programlisting>
<literal>Advised</literal> interface and examining and manipulating its
advice:</para>
<para><programlisting>Advised advised = (Advised) myObject;
<para><programlisting language="java">Advised advised = (Advised) myObject;
Advisor[] advisors = advised.getAdvisors();
int oldAdvisorCount = advisors.length;
System.out.println(oldAdvisorCount + " advisors");
@ -1438,7 +1438,7 @@ assertEquals("Added two advisors",
<literal>BeanPostProcessor</literal> that automatically creates AOP proxies
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="interceptorNames"&gt;
&lt;list&gt;
@ -1513,7 +1513,7 @@ assertEquals("Added two advisors",
return an AOP proxy, not the target business object. (The "inner bean"
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;property name="transactionInterceptor" ref="transactionInterceptor"/&gt;
@ -1586,7 +1586,7 @@ assertEquals("Added two advisors",
following code, in <literal>/WEB-INF/declarativeServices.xml</literal>.
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;property name="transactionInterceptor" ref="transactionInterceptor"/&gt;
@ -1627,7 +1627,7 @@ assertEquals("Added two advisors",
annotation, leading to implicit proxies for beans containing that
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;property name="transactionInterceptor" ref="transactionInterceptor"/&gt;
@ -1647,7 +1647,7 @@ assertEquals("Added two advisors",
be specific to the application's transaction requirements (typically
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>
<tip>
@ -1684,7 +1684,7 @@ assertEquals("Added two advisors",
generic <literal>DefaultPointcutAdvisor</literal>, configured using
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;
&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
on HotSwappableTargetSource as follows:</para>
<para><programlisting>HotSwappableTargetSource swapper =
<para><programlisting language="java">HotSwappableTargetSource swapper =
(HotSwappableTargetSource) beanFactory.getBean("swapper");
Object oldTarget = swapper.swap(newTarget);</programlisting></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;constructor-arg ref="initialTarget"/&gt;
@ -1796,7 +1796,7 @@ Object oldTarget = swapper.swap(newTarget);</programlisting></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;
... properties omitted
&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
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="targetMethod" value="getPoolingConfigMixin"/&gt;
&lt;/bean&gt;</programlisting></para>
@ -1845,7 +1845,7 @@ Object oldTarget = swapper.swap(newTarget);</programlisting></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>
<note>
@ -1873,7 +1873,7 @@ System.out.println("Max pool size is " + conf.getMaxSize());]]></programlisting>
<literal>poolTargetSource</literal> definition shown above as follows.
(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"/>
</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
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"/>
</bean>]]></programlisting>

View File

@ -327,7 +327,7 @@
<para>The @AspectJ support is enabled by including the following element
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
<xref linkend="xsd-config" />. See <xref
@ -338,7 +338,7 @@
support by adding the following definition to your application
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
application: <filename class="libraryfile">aspectjweaver.jar</filename>
@ -364,7 +364,7 @@
a bean class that has the <interfacename>@Aspect</interfacename>
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>
&lt;/bean&gt;
</programlisting>
@ -374,7 +374,7 @@
<interfacename>org.aspectj.lang.annotation.Aspect</interfacename>
annotation;</para>
<programlisting>package org.xyz;
<programlisting language="java">package org.xyz;
import org.aspectj.lang.annotation.Aspect;
@Aspect
@ -419,7 +419,7 @@ public class NotVeryUsefulAspect {
a pointcut named <literal>'anyOldTransfer'</literal> that will match the
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>
<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
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
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
trading module).</para>
<programlisting> @Pointcut("execution(public * *(..))")
<programlisting language="java"> @Pointcut("execution(public * *(..))")
private void anyPublicOperation() {}
@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
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.Pointcut;
@ -681,7 +681,7 @@ public class SystemArchitecture {
anywhere that you need a pointcut expression. For example, to make the
service layer transactional, you could write:</para>
<programlisting>&lt;aop:config&gt;
<programlisting language="xml">&lt;aop:config&gt;
&lt;aop:advisor
pointcut="com.xyz.someapp.SystemArchitecture.businessService()"
advice-ref="tx-advice"/&gt;
@ -706,7 +706,7 @@ public class SystemArchitecture {
<literal>execution</literal> pointcut designator the most often. The
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>
<para>All parts except the returning type pattern (ret-type-pattern in
@ -736,49 +736,49 @@ public class SystemArchitecture {
<listitem>
<para>the execution of any public method:</para>
<programlisting>execution(public * *(..))</programlisting>
<programlisting language="java">execution(public * *(..))</programlisting>
</listitem>
<listitem>
<para>the execution of any method with a name beginning with
"set":</para>
<programlisting>execution(* set*(..))</programlisting>
<programlisting language="java">execution(* set*(..))</programlisting>
</listitem>
<listitem>
<para>the execution of any method defined by the
<interfacename>AccountService</interfacename> interface:</para>
<programlisting>execution(* com.xyz.service.AccountService.*(..))</programlisting>
<programlisting language="java">execution(* com.xyz.service.AccountService.*(..))</programlisting>
</listitem>
<listitem>
<para>the execution of any method defined in the service
package:</para>
<programlisting>execution(* com.xyz.service.*.*(..))</programlisting>
<programlisting language="java">execution(* com.xyz.service.*.*(..))</programlisting>
</listitem>
<listitem>
<para>the execution of any method defined in the service package
or a sub-package:</para>
<programlisting>execution(* com.xyz.service..*.*(..))</programlisting>
<programlisting language="java">execution(* com.xyz.service..*.*(..))</programlisting>
</listitem>
<listitem>
<para>any join point (method execution only in Spring AOP) within
the service package:</para>
<programlisting>within(com.xyz.service.*)</programlisting>
<programlisting language="java">within(com.xyz.service.*)</programlisting>
</listitem>
<listitem>
<para>any join point (method execution only in Spring AOP) within
the service package or a sub-package:</para>
<programlisting>within(com.xyz.service..*)</programlisting>
<programlisting language="java">within(com.xyz.service..*)</programlisting>
</listitem>
<listitem>
@ -786,7 +786,7 @@ public class SystemArchitecture {
the proxy implements the
<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 :-
see the following section on advice for how to make the proxy
@ -798,7 +798,7 @@ public class SystemArchitecture {
the target object implements the
<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 :-
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
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
following section on advice for how to make the method arguments
@ -829,7 +829,7 @@ public class SystemArchitecture {
the target object has an
<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
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
<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
the following section on advice for how to make the annotation
@ -853,7 +853,7 @@ public class SystemArchitecture {
the executing method has an
<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 :-
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>
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
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
Spring bean named '<literal>tradeService</literal>':</para>
<programlisting>bean(tradeService)</programlisting>
<programlisting language="java">bean(tradeService)</programlisting>
</listitem>
<listitem>
@ -885,7 +885,7 @@ public class SystemArchitecture {
Spring beans having names that match the wildcard expression
'<literal>*Service</literal>':</para>
<programlisting>bean(*Service)</programlisting>
<programlisting language="java">bean(*Service)</programlisting>
</listitem>
</itemizedlist>
</section>
@ -905,7 +905,7 @@ public class SystemArchitecture {
<para>Before advice is declared in an aspect using the
<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;
@Aspect
@ -921,7 +921,7 @@ public class BeforeExample {
<para>If using an in-place pointcut expression we could rewrite the
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;
@Aspect
@ -942,7 +942,7 @@ public class BeforeExample {
returns normally. It is declared using the
<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;
@Aspect
@ -965,7 +965,7 @@ public class AfterReturningExample {
<interfacename>@AfterReturning</interfacename> that binds the return
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;
@Aspect
@ -1001,7 +1001,7 @@ public class AfterReturningExample {
by throwing an exception. It is declared using the
<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;
@Aspect
@ -1022,7 +1022,7 @@ public class AfterThrowingExample {
otherwise) and bind the thrown exception to an advice
parameter.</para>
<programlisting>import org.aspectj.lang.annotation.Aspect;
<programlisting language="java">import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.AfterThrowing;
@Aspect
@ -1055,7 +1055,7 @@ public class AfterThrowingExample {
exception return conditions. It is typically used for releasing
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;
@Aspect
@ -1111,7 +1111,7 @@ public class AfterFinallyExample {
AspectJ, and this is discussed in the following section on advice
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.ProceedingJoinPoint;
@ -1184,7 +1184,7 @@ public class AroundExample {
Account object as the first parameter, and you need access to the
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,..)")
public void validateAccount(Account account) {
<lineannotation>// ...</lineannotation>
@ -1203,7 +1203,7 @@ public void validateAccount(Account account) {
matches a join point, and then just refer to the named pointcut from
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,..)")
private void accountDataAccessOperation(Account account) {}
@ -1226,7 +1226,7 @@ public void validateAccount(Account account) {
<para>First the definition of the
<interfacename>@Auditable</interfacename> annotation:</para>
<programlisting>@Retention(RetentionPolicy.RUNTIME)
<programlisting language="java">@Retention(RetentionPolicy.RUNTIME)
@Target(ElementType.METHOD)
public @interface Auditable {
AuditCode value();
@ -1235,7 +1235,7 @@ public @interface Auditable {
<para>And then the advice that matches the execution of
<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)")
public void audit(Auditable auditable) {
AuditCode code = auditable.value();
@ -1263,7 +1263,7 @@ public void audit(Auditable auditable) {
<emphasis>are</emphasis> available at runtime. For
example:</para>
<programlisting>@Before(
<programlisting language="java">@Before(
value="com.xyz.lib.Pointcuts.anyPublicMethod() &amp;&amp; target(bean) &amp;&amp; @annotation(auditable)",
argNames="bean,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"
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)",
argNames="bean,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
declare the "argNames" attribute:</para>
<programlisting>@Before(
<programlisting language="java">@Before(
"com.xyz.lib.Pointcuts.anyPublicMethod()")
public void audit(JoinPoint jp) {
<lineannotation>// ... use jp</lineannotation>
@ -1355,7 +1355,7 @@ public void audit(JoinPoint jp) {
to ensure that the advice signature binds each of the method
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; " +
"args(accountHolderNamePattern)")
public Object preProcessQueryPattern(ProceedingJoinPoint pjp, String accountHolderNamePattern)
@ -1423,7 +1423,7 @@ throws Throwable {
implement the <interfacename>UsageTracked</interfacename> interface. (In
order to expose statistics via JMX for example.)</para>
<programlisting>@Aspect
<programlisting language="java">@Aspect
public class UsageTracking {
@DeclareParents(value="com.xzy.myapp.service.*+",
@ -1447,7 +1447,7 @@ public class UsageTracking {
<interfacename>UsageTracked</interfacename> interface. If accessing a
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 id="aop-instantiation-models">
@ -1469,7 +1469,7 @@ public class UsageTracking {
<interfacename>@Aspect</interfacename> annotation. Let's look at an
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 {
private int someState;
@ -1519,7 +1519,7 @@ public class MyAspect {
advice so that we can call proceed multiple times. Here's how the basic
aspect implementation looks:</para>
<programlisting>@Aspect
<programlisting language="java">@Aspect
public class ConcurrentOperationExecutor implements Ordered {
private static final int DEFAULT_MAX_RETRIES = 2;
@ -1573,7 +1573,7 @@ public class ConcurrentOperationExecutor implements Ordered {
<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"
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>
annotation:</para>
<programlisting>@Retention(RetentionPolicy.RUNTIME)
<programlisting language="java">@Retention(RetentionPolicy.RUNTIME)
public @interface Idempotent {
<lineannotation>// marker annotation</lineannotation>
}</programlisting>
@ -1595,7 +1595,7 @@ public @interface Idempotent {
simply involves refining the pointcut expression so that only
<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)")
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>
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&gt;
@ -1678,7 +1678,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
<para>A pointcut representing the execution of any business service in
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"
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
the above pointcut would be:</para>
<programlisting>&lt;aop:config&gt;
<programlisting language="xml">&lt;aop:config&gt;
&lt;aop:pointcut id="businessService"
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
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;
@ -1725,7 +1725,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
example, the following pointcut collects the 'this' object as the join
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;
@ -1741,7 +1741,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
<para>The advice must be declared to receive the collected join point
context by including parameters of the matching names:</para>
<programlisting>public void monitor(Object service) {
<programlisting language="java">public void monitor(Object service) {
...
}</programlisting>
@ -1750,7 +1750,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
used in place of '&amp;&amp;', '||' and '!' respectively. For example,
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;
@ -1784,7 +1784,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
declared inside an <literal>&lt;aop:aspect&gt;</literal> using the
&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
pointcut-ref="dataAccessOperation"
@ -1800,7 +1800,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
<literal>pointcut-ref</literal> attribute with a
<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
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
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
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
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
pointcut-ref="dataAccessOperation"
@ -1862,7 +1862,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
matching in the same way as described for @AfterReturning. For
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 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
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
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
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
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,
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 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>
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
pointcut-ref="dataAccessOperation"
@ -1951,7 +1951,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
linkend="aop-ataspectj-around-advice" /> for notes on calling proceed
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
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
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>
Object retVal = pjp.proceed();
<lineannotation>// stop stopwatch</lineannotation>
@ -1987,7 +1987,7 @@ public Object doConcurrentOperation(ProceedingJoinPoint pjp) throws Throwable {
attribute in an advice annotation as described in <xref
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)"
method="audit"
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
a number of strongly typed parameters.</para>
<programlisting>package x.y.service;
<programlisting language="java">package x.y.service;
public interface FooService {
@ -2021,7 +2021,7 @@ public class DefaultFooService implements FooService {
<methodname>profile(..)</methodname> is to be used as
<literal>around</literal> advice:</para>
<programlisting>package x.y;
<programlisting language="java">package x.y;
import org.aspectj.lang.ProceedingJoinPoint;
import org.springframework.util.StopWatch;
@ -2045,7 +2045,7 @@ public class SimpleProfiler {
effect the execution of the above advice for a particular join
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:aop="http://www.springframework.org/schema/aop"
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
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 x.y.service.FooService;
@ -2128,7 +2128,7 @@ ms % Task name
<interfacename>UsageTracked</interfacename> interface. (In order to
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
types-matching="com.xzy.myapp.service.*+"
@ -2145,7 +2145,7 @@ ms % Task name
<para>The class backing the <literal>usageTracking</literal> bean would
contain the method:</para>
<programlisting>public void recordUsage(UsageTracked usageTracked) {
<programlisting language="java">public void recordUsage(UsageTracked usageTracked) {
usageTracked.incrementUseCount();
}</programlisting>
@ -2159,7 +2159,7 @@ ms % Task name
interface. If accessing a 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 id="aop-schema-instatiation-models">
@ -2186,7 +2186,7 @@ ms % Task name
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>
<programlisting>&lt;aop:config&gt;
<programlisting language="xml">&lt;aop:config&gt;
&lt;aop:pointcut id="businessService"
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
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;
@ -2288,7 +2288,7 @@ ms % Task name
<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;
@ -2315,7 +2315,7 @@ ms % Task name
introducing an <interfacename>Idempotent</interfacename>
annotation:</para>
<programlisting>@Retention(RetentionPolicy.RUNTIME)
<programlisting language="java">@Retention(RetentionPolicy.RUNTIME)
public @interface Idempotent {
<lineannotation>// marker annotation</lineannotation>
}</programlisting>
@ -2325,7 +2325,7 @@ public @interface Idempotent {
simply involves refining the pointcut expression so that only
<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
@annotation(com.xyz.myapp.service.Idempotent)"/&gt;</programlisting>
</section>
@ -2401,7 +2401,7 @@ public @interface Idempotent {
in XML. For example, in the @AspectJ style you can write something
like:</para>
<programlisting> @Pointcut(execution(* get*()))
<programlisting language="java"> @Pointcut(execution(* get*()))
public void propertyAccess() {}
@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>
<programlisting> &lt;aop:pointcut id="propertyAccess"
<programlisting language="xml"> &lt;aop:pointcut id="propertyAccess"
expression="execution(* get*())"/&gt;
&lt;aop:pointcut id="operationReturningAnAccount"
@ -2492,7 +2492,7 @@ public @interface Idempotent {
the value of the <literal>proxy-target-class</literal> attribute of the
<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>
&lt;/aop:config&gt;</programlisting>
@ -2501,7 +2501,7 @@ public @interface Idempotent {
<literal>&lt;aop:aspectj-autoproxy&gt;</literal> element to
<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>
<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
illustrated by the following code snippet.</para>
<programlisting>public class SimplePojo implements Pojo {
<programlisting language="java">public class SimplePojo implements Pojo {
public void foo() {
<lineannotation>// this next method invocation is a <emphasis
@ -2562,7 +2562,7 @@ public @interface Idempotent {
</imageobject>
</mediaobject></para>
<programlisting>public class Main {
<programlisting language="java">public class Main {
public static void main(String[] args) {
@ -2588,7 +2588,7 @@ public @interface Idempotent {
</imageobject>
</mediaobject></para>
<programlisting>public class Main {
<programlisting language="java">public class Main {
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
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() {
<lineannotation>// this works, but... gah!</lineannotation>
@ -2646,7 +2646,7 @@ public @interface Idempotent {
It also requires some additional configuration when the proxy is being
created:</para>
<programlisting>public class Main {
<programlisting language="java">public class Main {
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
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);
<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
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;
@ -2757,14 +2757,14 @@ public class Account {
way to declare the prototype definition is simply to omit the
<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;/bean&gt;</programlisting>
<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>
<programlisting>package com.xyz.myapp.domain;
<programlisting language="java">package com.xyz.myapp.domain;
import org.springframework.beans.factory.annotation.Configurable;
@ -2827,7 +2827,7 @@ public class Account {
<interfacename>@Configurable</interfacename> declaration like
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
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
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
definition is:</para>
<programlisting>&lt;bean
<programlisting language="xml">&lt;bean
class="org.springframework.beans.factory.aspectj.AnnotationBeanConfigurerAspect"
factory-method="aspectOf"/&gt;</programlisting>
@ -2868,7 +2868,7 @@ public class Account {
manually specify that the bean depends on the configuration
aspect.</para>
<programlisting>&lt;bean id="myService"
<programlisting language="xml">&lt;bean id="myService"
class="com.xzy.myapp.service.MyService"
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
fully-qualified class names:</para>
<programlisting>public aspect DomainObjectConfiguration extends AbstractBeanConfigurerAspect {
<programlisting language="java">public aspect DomainObjectConfiguration extends AbstractBeanConfigurerAspect {
public DomainObjectConfiguration() {
setBeanWiringInfoResolver(new ClassNameBeanWiringInfoResolver());
@ -3014,7 +3014,7 @@ public class Account {
ensures that Spring obtains the aspect instance by asking AspectJ for it
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;
&lt;property name="profilingStrategy" ref="jamonProfilingStrategy"/&gt;
&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
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="thatBean"/&gt;
&lt;/aop:aspectj-autoproxy&gt;</programlisting>
@ -3108,7 +3108,7 @@ public class Account {
quick-and-dirty time-based profiler, using the @AspectJ-style of
aspect declaration.</para>
<programlisting>package foo;
<programlisting language="java">package foo;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Aspect;
@ -3145,7 +3145,7 @@ public class ProfilingAspect {
classpath called ' <filename>META-INF/aop.xml</filename>' is standard
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;
&lt;aspectj&gt;
@ -3175,7 +3175,7 @@ public class ProfilingAspect {
are some more options that you can specify, but these are detailed
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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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
action.</para>
<programlisting>package foo;
<programlisting language="java">package foo;
import org.springframework.context.support.ClassPathXmlApplicationContext;
@ -3256,7 +3256,7 @@ ms % Task name
on the <classname>Main</classname> program will yield the same
result.</para>
<programlisting>package foo;
<programlisting language="java">package foo;
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>
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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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
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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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
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"
useSystemClassLoaderAsParent="false"/&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
resources.</para>
<programlisting><![CDATA[public interface Resource extends InputStreamSource {
<programlisting language="java"><![CDATA[public interface Resource extends InputStreamSource {
boolean exists();
@ -44,7 +44,7 @@
String getDescription();
}]]></programlisting>
<programlisting><![CDATA[public interface InputStreamSource {
<programlisting language="java"><![CDATA[public interface InputStreamSource {
InputStream getInputStream() throws IOException;
}]]></programlisting>
@ -244,7 +244,7 @@
to be implemented by objects that can return (i.e. load)
<interfacename>Resource</interfacename> instances.</para>
<programlisting>public interface ResourceLoader {
<programlisting language="java">public interface ResourceLoader {
Resource getResource(String location);
}</programlisting>
@ -261,7 +261,7 @@
of code was executed against a
<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
<classname>ClassPathResource</classname>; if the same method was executed
@ -278,15 +278,15 @@
application context type, by specifying the special
<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
used by specifying any of the standard <classname>java.net.URL</classname>
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
<classname>String</classname>s to
@ -361,7 +361,7 @@
a special marker interface, identifying objects that expect to be provided
with a <interfacename>ResourceLoader</interfacename> reference.</para>
<programlisting><![CDATA[public interface ResourceLoaderAware {
<programlisting language="java"><![CDATA[public interface ResourceLoaderAware {
void setResourceLoader(ResourceLoader resourceLoader);
}]]></programlisting>
@ -427,7 +427,7 @@
<interfacename>Resource</interfacename>, it can be configured with a
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"/>
</bean>]]></programlisting>
@ -446,9 +446,9 @@
<classname>UrlResource</classname> (the latter being used to access a
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 id="resources-app-ctx">
@ -468,7 +468,7 @@
specific application context. For example, if you create a
<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
<classname></classname><classname>ClassPathResource</classname> will be
@ -476,7 +476,7 @@
<classname>FileSystemXmlApplicationContext</classname> as
follows:</para>
<programlisting><![CDATA[ApplicationContext ctx =
<programlisting language="java"><![CDATA[ApplicationContext ctx =
new FileSystemXmlApplicationContext("conf/appContext.xml");]]></programlisting>
<para>The bean definition will be loaded from a filesystem location, in
@ -487,7 +487,7 @@
<interfacename>Resource</interfacename> created to load the definition.
So this <classname>FileSystemXmlApplicationContext</classname>...</para>
<programlisting><![CDATA[ApplicationContext ctx =
<programlisting language="java"><![CDATA[ApplicationContext ctx =
new FileSystemXmlApplicationContext("classpath:conf/appContext.xml");]]></programlisting>
<para>... will actually load its bean definitions from the classpath.
@ -521,7 +521,7 @@
and <literal>'daos.xml'</literal> could be instantiated like
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>
<para>Please do consult the Javadocs for the
@ -617,7 +617,7 @@
string may use the special <literal>classpath*:</literal>
prefix:</para>
<programlisting><![CDATA[ApplicationContext ctx =
<programlisting language="java"><![CDATA[ApplicationContext ctx =
new ClassPathXmlApplicationContext("classpath*:conf/appContext.xml");]]></programlisting>
<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
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>
<programlisting><![CDATA[ApplicationContext ctx =
<programlisting language="java"><![CDATA[ApplicationContext ctx =
new FileSystemXmlApplicationContext("/conf/context.xml");]]></programlisting>
<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>
<programlisting><![CDATA[FileSystemXmlApplicationContext ctx = ...;
<programlisting language="java"><![CDATA[FileSystemXmlApplicationContext ctx = ...;
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>
<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
<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>
<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 =
new FileSystemXmlApplicationContext("file:/conf/context.xml");]]></programlisting>
</section>

View File

@ -468,7 +468,7 @@
the test will be enabled. This annotation can be applied to an
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() {
<lineannotation>// some logic that should run only on Java VMs from Sun Microsystems</lineannotation>
}</programlisting>
@ -479,7 +479,7 @@ public void testProcessWhichRunsOnlyOnSunJvm() {
for <emphasis>test groups</emphasis> in a JUnit environment.
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() {
<lineannotation>// some logic that should run only for unit and integration test groups</lineannotation>
}</programlisting>
@ -498,7 +498,7 @@ public void testProcessWhichRunsForUnitOrIntegrationTestGroups() {
<classname>SystemProfileValueSource</classname> will be used by
default.</para>
<programlisting>@ProfileValueSourceConfiguration(CustomProfileValueSource.class)
<programlisting language="java">@ProfileValueSourceConfiguration(CustomProfileValueSource.class)
public class CustomProfileValueSourceTests {
<lineannotation>// class body...</lineannotation>
}</programlisting>
@ -514,7 +514,7 @@ public class CustomProfileValueSourceTests {
test method finishes execution (regardless of whether the test
passed or not).</para>
<programlisting>@DirtiesContext
<programlisting language="java">@DirtiesContext
public void testProcessWhichDirtiesAppCtx() {
<lineannotation>// some logic that results in the Spring container being dirtied</lineannotation>
}</programlisting>
@ -531,7 +531,7 @@ public void testProcessWhichDirtiesAppCtx() {
Likewise if an instance of the exception is <emphasis>not</emphasis>
thrown during the test method execution then the test fails.</para>
<programlisting>@ExpectedException(SomeBusinessException.class)
<programlisting language="java">@ExpectedException(SomeBusinessException.class)
public void testProcessRainyDayScenario() {
<lineannotation>// some logic that should result in an <classname>Exception</classname> being thrown</lineannotation>
}</programlisting>
@ -552,7 +552,7 @@ public void testProcessRainyDayScenario() {
<emphasis>set up</emphasis> or <emphasis>tear down</emphasis> of the
test fixture.</para>
<programlisting>@Timed(millis=1000)
<programlisting language="java">@Timed(millis=1000)
public void testProcessWithOneSecondTimeout() {
<lineannotation>// some logic that should not take longer than 1 second to execute</lineannotation>
}</programlisting>
@ -571,7 +571,7 @@ public void testProcessWithOneSecondTimeout() {
up</emphasis> or <emphasis>tear down</emphasis> of the test
fixture.</para>
<programlisting>@Repeat(10)
<programlisting language="java">@Repeat(10)
public void testProcessRepeatedly() {
<lineannotation>// ...</lineannotation>
}</programlisting>
@ -588,7 +588,7 @@ public void testProcessRepeatedly() {
committed. Use <interfacename>@Rollback</interfacename> to override
the default rollback flag configured at the class level.</para>
<programlisting>@Rollback(false)
<programlisting language="java">@Rollback(false)
public void testProcessWithoutRollback() {
<lineannotation>// ...</lineannotation>
}</programlisting>
@ -602,7 +602,7 @@ public void testProcessWithoutRollback() {
test method must <emphasis>not</emphasis> execute in a transactional
context.</para>
<programlisting>@NotTransactional
<programlisting language="java">@NotTransactional
public void testProcessWithoutTransaction() {
<lineannotation>// ...</lineannotation>
}</programlisting>
@ -659,7 +659,7 @@ public void testProcessWithoutTransaction() {
and exposes a <literal>protected</literal> method that subclasses can
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
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
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
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
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> {
<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
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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.springframework.org/schema/beans
@ -785,7 +785,7 @@ public void testProcessWithoutTransaction() {
configuration does not need to change, merely the test
fixture).</para>
<programlisting>public final class HibernateTitleDaoTests <emphasis
<programlisting language="java">public final class HibernateTitleDaoTests <emphasis
role="bold">extends AbstractDependencyInjectionSpringContextTests</emphasis> {
public HibernateTitleDaoTests() {
@ -1096,7 +1096,7 @@ public void testProcessWithoutTransaction() {
application context from
<literal>"classpath:/com/example/MyTest-context.xml"</literal>.</para>
<programlisting>package com.example;
<programlisting language="java">package com.example;
@RunWith(SpringJUnit4ClassRunner.class)
<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
<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>// in the root of the classpath</lineannotation>
<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
"/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>
<emphasis role="bold">@ContextConfiguration(locations={"/base-context.xml"})</emphasis>
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
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>
<emphasis role="bold">@ContextConfiguration(locations={"daos.xml"})</emphasis>
public final class HibernateTitleDaoTests {
@ -1266,7 +1266,7 @@ public final class HibernateTitleDaoTests {
<para>Alternatively, we can configure the class to use
<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>
<emphasis role="bold">@ContextConfiguration(locations={"daos.xml"})</emphasis>
public final class HibernateTitleDaoTests {
@ -1291,7 +1291,7 @@ public final class HibernateTitleDaoTests {
<para>Now let's take a look at an example using
<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>
<emphasis role="bold">@ContextConfiguration(locations={"daos.xml"})</emphasis>
public final class HibernateTitleDaoTests {
@ -1312,7 +1312,7 @@ public final class HibernateTitleDaoTests {
<para>Finally, here is an example using
<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>
<emphasis role="bold">@ContextConfiguration(locations={"daos.xml"})</emphasis>
public final class HibernateTitleDaoTests {
@ -1338,7 +1338,7 @@ public final class HibernateTitleDaoTests {
by the <interfacename>@ContextConfiguration</interfacename> annotation
(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"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
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>
annotation to indicate a specific target bean as follows:</para>
<programlisting>...
<programlisting language="java">...
@Override @Autowired
public void setDataSource(<emphasis role="bold">@Qualifier("myDataSource")</emphasis> DataSource dataSource) {
super.setDataSource(dataSource);
@ -1389,7 +1389,7 @@ public final class HibernateTitleDaoTests {
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>
<programlisting>...
<programlisting language="java">...
@Override <emphasis role="bold">@Resource("myDataSource")</emphasis>
public void setDataSource(DataSource dataSource) {
super.setDataSource(dataSource);
@ -1479,7 +1479,7 @@ public final class HibernateTitleDaoTests {
support</link> section of the reference manual for further information
and configuration examples.</para>
<programlisting>@RunWith(SpringJUnit4ClassRunner.class)
<programlisting language="java">@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration
<emphasis role="bold">@TransactionConfiguration(transactionManager="txMgr", defaultRollback=false)</emphasis>
<emphasis role="bold">@Transactional</emphasis>
@ -1695,7 +1695,7 @@ public class FictitiousTransactionalTest {
<interfacename>ApplicationContext</interfacename> be configured via
<interfacename>@ContextConfiguration</interfacename>.</emphasis></para>
<programlisting>@RunWith(SpringJUnit4ClassRunner.class)
<programlisting language="java">@RunWith(SpringJUnit4ClassRunner.class)
@TestExecutionListeners({})
public class SimpleTest {
@ -1913,7 +1913,7 @@ public class SimpleTest {
<interfacename>ContextLoader</interfacename> strategy to use for
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 {
<lineannotation>// class body...</lineannotation>
}</programlisting>
@ -1937,7 +1937,7 @@ public class CustomConfiguredApplicationContextTests {
will be used in conjunction with
<interfacename>@ContextConfiguration</interfacename>.</para>
<programlisting>@ContextConfiguration
<programlisting language="java">@ContextConfiguration
@TestExecutionListeners({CustomTestExecutionListener.class, AnotherTestExecutionListener.class})
public class CustomTestExecutionListenerTests {
<lineannotation>// class body...</lineannotation>
@ -1965,7 +1965,7 @@ public class CustomTestExecutionListenerTests {
used in conjunction with
<interfacename>@ContextConfiguration</interfacename>.</para>
<programlisting>@ContextConfiguration
<programlisting language="java">@ContextConfiguration
@TransactionConfiguration(transactionManager="txMgr", defaultRollback=false)
public class CustomConfiguredTransactionalTests {
<lineannotation>// class body...</lineannotation>
@ -1982,7 +1982,7 @@ public class CustomConfiguredTransactionalTests {
transaction via the <interfacename>@Transactional</interfacename>
annotation.</para>
<programlisting>@BeforeTransaction
<programlisting language="java">@BeforeTransaction
public void beforeTransaction() {
<lineannotation>// logic to be executed before a transaction is started</lineannotation>
}</programlisting>
@ -1998,7 +1998,7 @@ public void beforeTransaction() {
transaction via the <interfacename>@Transactional</interfacename>
annotation.</para>
<programlisting>@AfterTransaction
<programlisting language="java">@AfterTransaction
public void afterTransaction() {
<lineannotation>// logic to be executed after a transaction has ended</lineannotation>
}</programlisting>
@ -2019,7 +2019,7 @@ public void afterTransaction() {
<classname>AbstractClinicTests</classname>, for which a partial listing
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> {
<emphasis role="bold">@Autowired</emphasis>
@ -2106,7 +2106,7 @@ public abstract class AbstractClinicTests <emphasis role="bold">extends Abstract
overriding beans defined in
<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 { }
</programlisting>

View File

@ -43,7 +43,7 @@
an <interfacename>Errors</interfacename> object so that while validating, validators can report
validation failures to the <interfacename>Errors</interfacename> object.</para>
<para>Let's consider a small data object:</para>
<programlisting><![CDATA[
<programlisting language="java"><![CDATA[
public class Person {
private String name;
@ -71,7 +71,7 @@ public class Person {
Implementing a <interfacename>Validator</interfacename> is fairly straightforward,
especially when you know of the <classname>ValidationUtils</classname> helper class
that the Spring Framework also provides.</para>
<programlisting><![CDATA[public class PersonValidator implements Validator {
<programlisting language="java"><![CDATA[public class PersonValidator implements Validator {
]]><lineannotation>/**
* 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
dependency-inject or instantiate an <classname>AddressValidator</classname> within your
<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;
@ -285,7 +285,7 @@ public class Person {
<interfacename>PropertyEditors</interfacename>.)</emphasis></para>
<para>Consider the following two classes:</para>
<programlisting><![CDATA[public class Company {
<programlisting language="java"><![CDATA[public class Company {
private String name;
private Employee managingDirector;
@ -303,7 +303,7 @@ public class Person {
}
}]]></programlisting>
<programlisting><![CDATA[public class Employee {
<programlisting language="java"><![CDATA[public class Employee {
private String name;
private float salary;
@ -324,7 +324,7 @@ public class Person {
<para>The following code snippets show some examples of how to retrieve
and manipulate some of the properties of instantiated
<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[
company.setPropertyValue("name", "Some Company Inc.");
]]><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>
property of the <classname>Foo</classname> class.
</para>
<programlisting><![CDATA[public class FooBeanInfo extends SimpleBeanInfo {
<programlisting language="java"><![CDATA[public class FooBeanInfo extends SimpleBeanInfo {
public PropertyDescriptor[] getPropertyDescriptors() {
try {
@ -602,7 +602,7 @@ Float salary = (Float) company.getPropertyValue("managingDirector.salary");]]></
<para>Consider a user class <classname>ExoticType</classname>, and another class
<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 {
@ -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
<interfacename>PropertyEditor</interfacename> will behind the scenes convert into an actual
<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"/>
</bean>]]></programlisting>
<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;
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
<interfacename>PropertyEditor</interfacename> with the <interfacename>ApplicationContext</interfacename>,
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">
<map>
<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>
implementation:</para>
<programlisting><![CDATA[package com.foo.editors.spring;
<programlisting language="java"><![CDATA[package com.foo.editors.spring;
public final class CustomPropertyEditorRegistrar implements PropertyEditorRegistrar {
@ -702,7 +702,7 @@ public final class CustomPropertyEditorRegistrar implements PropertyEditorRegist
of each property editor.</para>
<para>Next we configure a <classname>CustomEditorConfigurer</classname> and inject an
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">
<list>
<ref bean="customPropertyEditorRegistrar"/>
@ -719,7 +719,7 @@ public final class CustomPropertyEditorRegistrar implements PropertyEditorRegist
<interfacename>PropertyEditorRegistrar</interfacename> in the implementation of an <methodname>initBinder(..)</methodname>
method:</para>
<programlisting><![CDATA[public final class RegisterUserController extends SimpleFormController {
<programlisting language="java"><![CDATA[public final class RegisterUserController extends SimpleFormController {
private final PropertyEditorRegistrar customPropertyEditorRegistrar;