Spring FrameworkSpring AOP: Aspect Oriented Programming with Spring

Traducteur:  
(Dernière date de traduction:  )
Relecteur:  
(Dernière date de relecture:  )
Index des chapitres

Légende:
       à revoir
       non compris
       à faire
       non traduit ( laissé tel quel )

chapter
+ titleRef.   /chapter[1]/title[1]
OriginalTraduction
Spring AOP: Aspect Oriented Programming with Spring  
sect1
+ titleRef.   /chapter[1]/sect1[1]/title[1]
OriginalTraduction
Concepts  
+ paraRef.   /chapter[1]/sect1[1]/para[1]
OriginalTraduction
Aspect-Oriented Programming (AOP) complements OOP by providing another way of thinking about program structure. While OO decomposes applications into a hierarchy of objects, AOP decomposes programs into aspects or concerns. This enables modularization of concerns such as transaction management that would otherwise cut across multiple objects. (Such concerns are often termed crosscutting concerns.)  
+ paraRef.   /chapter[1]/sect1[1]/para[2]
OriginalTraduction
One of the key components of Spring is the AOP framework. While the Spring IoC containers (BeanFactory and ApplicationContext) do not depend on AOP, meaning you don't need to use AOP if you don't want to, AOP complements Spring IoC to provide a very capable middleware solution.  
+ paraRef.   /chapter[1]/sect1[1]/para[3]
OriginalTraduction
AOP is used in Spring:  
+ paraRef.   /chapter[1]/sect1[1]/itemizedlist[1]/listitem[1]/para[1]
OriginalTraduction
To provide declarative enterprise services, especially as a replacement for EJB declarative services. The most important such service is declarative transaction management, which builds on Spring's transaction abstraction.  
+ paraRef.   /chapter[1]/sect1[1]/itemizedlist[1]/listitem[2]/para[1]
OriginalTraduction
To allow users to implement custom aspects, complementing their use of OOP with AOP.  
+ paraRef.   /chapter[1]/sect1[1]/para[4]
OriginalTraduction
Thus you can view Spring AOP as either an enabling technology that allows Spring to provide declarative transaction management without EJB; or use the full power of the Spring AOP framework to implement custom aspects.  
+ remarkRef.   /chapter[1]/sect1[1]/remark[1]
OriginalTraduction
If you are interested only in generic declarative services or other pre-packaged declarative middleware services such as pooling, you don't need to work directly with Spring AOP, and can skip most of this chapter.  
sect2
+ titleRef.   /chapter[1]/sect1[1]/sect2[1]/title[1]
OriginalTraduction
AOP concepts  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/para[1]
OriginalTraduction
Let us begin by defining some central AOP concepts. These terms are not Spring-specific. Unfortunately, AOP terminology is not particularly intuitive. However, it would be even more confusing if Spring used its own terminology.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/itemizedlist[1]/listitem[1]/para[1]
OriginalTraduction
Aspect: A modularization of a concern for which the implementation might otherwise cut across multiple objects. Transaction management is a good example of a crosscutting concern in J2EE applications. Aspects are implemented using Spring as Advisors or interceptors.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/itemizedlist[1]/listitem[2]/para[1]
OriginalTraduction
Joinpoint: Point during the execution of a program, such as a method invocation or a particular exception being thrown. In Spring AOP, a joinpoint is always method invocation. Spring does not use the term joinpoint prominently; joinpoint information is accessible through methods on the MethodInvocation argument passed to interceptors, and is evaluated by implementations of the org.springframework.aop.Pointcut interface.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/itemizedlist[1]/listitem[3]/para[1]
OriginalTraduction
Advice: Action taken by the AOP framework at a particular joinpoint. Different types of advice include "around," "before" and "throws" advice. Advice types are discussed below. Many AOP frameworks, including Spring, model an advice as an interceptor, maintaining a chain of interceptors "around" the joinpoint.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/itemizedlist[1]/listitem[4]/para[1]
OriginalTraduction
Pointcut: A set of joinpoints specifying when an advice should fire. An AOP framework must allow developers to specify pointcuts: for example, using regular expressions.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/itemizedlist[1]/listitem[5]/para[1]
OriginalTraduction
Introduction: Adding methods or fields to an advised class. Spring allows you to introduce new interfaces to any advised object. For example, you could use an introduction to make any object implement an IsModified interface, to simplify caching.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/itemizedlist[1]/listitem[6]/para[1]
OriginalTraduction
Target object: Object containing the joinpoint. Also referred to as advised or proxied object.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/itemizedlist[1]/listitem[7]/para[1]
OriginalTraduction
AOP proxy: Object created by the AOP framework, including advice. In Spring, an AOP proxy will be a JDK dynamic proxy or a CGLIB proxy.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/itemizedlist[1]/listitem[8]/para[1]
OriginalTraduction
Weaving: Assembling aspects to create an advised object. This can be done at compile time (using the AspectJ compiler, for example), or at runtime. Spring, like other pure Java AOP frameworks, performs weaving at runtime.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/para[2]
OriginalTraduction
Different advice types include:  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/itemizedlist[2]/listitem[1]/para[1]
OriginalTraduction
Around advice: Advice that surrounds a joinpoint such as a method invocation. This is the most powerful kind of advice. Around advices will perform custom behavior before and after the method invocation. They are responsible for choosing whether to proceed to the joinpoint or to shortcut executing by returning their own return value or throwing an exception.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/itemizedlist[2]/listitem[2]/para[1]
OriginalTraduction
Before advice: Advice that executes before a joinpoint, but which does not have the ability to prevent execution flow proceeding to the joinpoint (unless it throws an exception).  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/itemizedlist[2]/listitem[3]/para[1]
OriginalTraduction
Throws advice: Advice to be executed if a method throws an exception. Spring provides strongly typed throws advice, so you can write code that catches the exception (and subclasses) you're interested in, without needing to cast from Throwable or Exception.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/itemizedlist[2]/listitem[4]/para[1]
OriginalTraduction
After returning advice: Advice to be executed after a joinpoint completes normally: for example, if a method returns without throwing an exception.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/para[3]
OriginalTraduction
Around advice is the most general kind of advice. Most interception-based AOP frameworks, such as Nanning Aspects, provide only around advice.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/para[4]
OriginalTraduction
As Spring, like AspectJ, provides a full range of advice types, we recommend that you use the least powerful advice type that can implement the required behavior. For example, if you need only to update a cache with the return value of a method, you are better off implementing an after returning advice than an around advice, although an around advice can accomplish the same thing. Using the most specific advice type provides a simpler programming model with less potential for errors. For example, you don't need to invoke the proceed() method on the MethodInvocation used for around advice, and hence can't fail to invoke it.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[1]/para[5]
OriginalTraduction
The pointcut concept is the key to AOP, distinguishing AOP from older technologies offering interception. Pointcuts enable advice to be targeted independently of the OO hierarchy. For example, an around advice providing declarative transaction management can be applied to a set of methods spanning multiple objects. Thus pointcuts provide the structural element of AOP.  
sect2
+ titleRef.   /chapter[1]/sect1[1]/sect2[2]/title[1]
OriginalTraduction
Spring AOP capabilities and goals  
+ paraRef.   /chapter[1]/sect1[1]/sect2[2]/para[1]
OriginalTraduction
Spring AOP is implemented in pure Java. There is no need for a special compilation process. Spring AOP does not need to control the class loader hierarchy, and is thus suitable for use in a J2EE web container or application server.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[2]/para[2]
OriginalTraduction
Spring currently supports interception of method invocations. Field interception is not implemented, although support for field interception could be added without breaking the core Spring AOP APIs.  
+ remarkRef.   /chapter[1]/sect1[1]/sect2[2]/remark[1]
OriginalTraduction
Field interception arguably violates OO encapsulation. We don't believe it is wise in application development. If you require field interception, consider using AspectJ.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[2]/para[3]
OriginalTraduction
Spring provides classes to represent pointcuts and different advice types. Spring uses the term advisor for an object representing an aspect, including both an advice and a pointcut targeting it to specific joinpoints.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[2]/para[4]
OriginalTraduction
Different advice types are MethodInterceptor (from the AOP Alliance interception API); and the advice interfaces defined in the org.springframework.aop package. All advices must implement the org.aopalliance.aop.Advice tag interface. Advices supported out the box are MethodInterceptor ; ThrowsAdvice; BeforeAdvice; and AfterReturningAdvice. We'll discuss advice types in detail below.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[2]/para[5]
OriginalTraduction
Spring implements the AOP Alliance interception interfaces (http://www.sourceforge.net/projects/aopalliance). Around advice must implement the AOP Alliance org.aopalliance.intercept.MethodInterceptor interface. Implementations of this interface can run in Spring or any other AOP Alliance compliant implementation. Currently JAC implements the AOP Alliance interfaces, and Nanning and Dynaop are likely to in early 2004.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[2]/para[6]
OriginalTraduction
Spring's approach to AOP differs from that of most other AOP frameworks. The aim is not to provide the most complete AOP implementation (although Spring AOP is quite capable); it is rather to provide a close integration between AOP implementation and Spring IoC to help solve common problems in enterprise applications.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[2]/para[7]
OriginalTraduction
Thus, for example, Spring's AOP functionality is normally used in conjunction with a Spring IoC container. AOP advice is specified using normal bean definition syntax (although this allows powerful "autoproxying" capabilities); advice and pointcuts are themselves managed by Spring IoC: a crucial difference from other AOP implementations. There are some things you can't do easily or efficiently with Spring AOP, such as advise very fine-grained objects. AspectJ is probably the best choice in such cases. However, our experience is that Spring AOP provides an excellent solution to most problems in J2EE applications that are amenable to AOP.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[2]/para[8]
OriginalTraduction
Spring AOP will never strive to compete with AspectJ or AspectWerkz to provide a comprehensive AOP solution. We believe that both proxy-based frameworks like Spring and full-blown frameworks such as AspectJ are valuable, and that they are complementary, rather than in competition. Thus a major priority for Spring 1.1 will be seamlessly integrating Spring AOP and IoC with AspectJ, to enable all uses of AOP to be catered for within a consistent Spring-based application architecture. This integration will not affect the Spring AOP API or the AOP Alliance API; Spring AOP will remain backward-compatible.  
sect2
+ titleRef.   /chapter[1]/sect1[1]/sect2[3]/title[1]
OriginalTraduction
AOP Proxies in Spring  
+ paraRef.   /chapter[1]/sect1[1]/sect2[3]/para[1]
OriginalTraduction
Spring defaults to using J2SE dynamic proxies for AOP proxies. This enables any interface or set of interfaces to be proxied.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[3]/para[2]
OriginalTraduction
Spring can also use CGLIB proxies. This is necessary to proxy classes, rather than interfaces. CGLIB is used by default if a business object doesn't implement an interface. As it's good practice to program to interfaces rather than classes, business objects normally will implement one or more business interfaces.  
+ paraRef.   /chapter[1]/sect1[1]/sect2[3]/para[3]
OriginalTraduction
It is possible to force the use of CGLIB: we'll discuss this below, and explain why you'd want to do this.  
+ remarkRef.   /chapter[1]/sect1[1]/sect2[3]/remark[1]
OriginalTraduction
Beyond Spring 1.0, Spring may offer additional types of AOP proxy, including wholly generated classes. This won't affect the programming model.  
sect1
+ titleRef.   /chapter[1]/sect1[2]/title[1]
OriginalTraduction
Pointcuts in Spring  
+ paraRef.   /chapter[1]/sect1[2]/para[1]
OriginalTraduction
Let's look at how Spring handles the crucial pointcut concept.  
sect2
+ titleRef.   /chapter[1]/sect1[2]/sect2[1]/title[1]
OriginalTraduction
Concepts  
+ paraRef.   /chapter[1]/sect1[2]/sect2[1]/para[1]
OriginalTraduction
Spring's pointcut model enables pointcut reuse independent of advice types. It's possible to target different advice using the same pointcut.  
+ paraRef.   /chapter[1]/sect1[2]/sect2[1]/para[2]
OriginalTraduction
The org.springframework.aop.Pointcut interface is the central interface, used to target advices to particular classes and methods. The complete interface is shown below:  
+ programlistingRef.   /chapter[1]/sect1[2]/sect2[1]/programlisting[1]
OriginalTraduction
public interface Pointcut {

    ClassFilter getClassFilter();

    MethodMatcher getMethodMatcher();

}
 
+ paraRef.   /chapter[1]/sect1[2]/sect2[1]/para[3]
OriginalTraduction
Splitting the Pointcut interface into two parts allows reuse of class and method matching parts, and fine-grained composition operations (such as performing a "union" with another method matcher).  
+ paraRef.   /chapter[1]/sect1[2]/sect2[1]/para[4]
OriginalTraduction
The ClassFilter interface is used to restrict the pointcut to a given set of target classes. If the matches() method always returns true, all target classes will be matched:  
+ programlistingRef.   /chapter[1]/sect1[2]/sect2[1]/programlisting[2]
OriginalTraduction
public interface ClassFilter {

    boolean matches(Class clazz);
}
 
+ paraRef.   /chapter[1]/sect1[2]/sect2[1]/para[5]
OriginalTraduction
The MethodMatcher interface is normally more important. The complete interface is shown below:  
+ programlistingRef.   /chapter[1]/sect1[2]/sect2[1]/programlisting[3]
OriginalTraduction
public interface MethodMatcher {

    boolean matches(Method m, Class targetClass);

    boolean isRuntime();

    boolean matches(Method m, Class targetClass, Object[] args);
}
 
+ paraRef.   /chapter[1]/sect1[2]/sect2[1]/para[6]
OriginalTraduction
The matches(Method, Class) method is used to test whether this pointcut will ever match a given method on a target class. This evaluation can be performed when an AOP proxy is created, to avoid the need for a test on every method invocation. If the 2-argument matches method returns true for a given method, and the isRuntime() method for the MethodMatcher returns true, the 3-argument matches method will be invoked on every method invocation. This enables a pointcut to look at the arguments passed to the method invocation immediately before the target advice is to execute.  
+ paraRef.   /chapter[1]/sect1[2]/sect2[1]/para[7]
OriginalTraduction
Most MethodMatchers are static, meaning that their isRuntime() method returns false. In this case, the 3-argument matches method will never be invoked.  
+ remarkRef.   /chapter[1]/sect1[2]/sect2[1]/remark[1]
OriginalTraduction
If possible, try to make pointcuts static, allowing the AOP framework to cache the results of pointcut evaluation when an AOP proxy is created.  
sect2
+ titleRef.   /chapter[1]/sect1[2]/sect2[2]/title[1]
OriginalTraduction
Operations on pointcuts  
+ paraRef.   /chapter[1]/sect1[2]/sect2[2]/para[1]
OriginalTraduction
Spring supports operations on pointcuts: notably, union and intersection.  
+ paraRef.   /chapter[1]/sect1[2]/sect2[2]/para[2]
OriginalTraduction
Union means the methods that either pointcut matches.  
+ paraRef.   /chapter[1]/sect1[2]/sect2[2]/para[3]
OriginalTraduction
Intersection means the methods that both pointcuts match.  
+ paraRef.   /chapter[1]/sect1[2]/sect2[2]/para[4]
OriginalTraduction
Union is usually more useful.  
+ paraRef.   /chapter[1]/sect1[2]/sect2[2]/para[5]
OriginalTraduction
Pointcuts can be composed using the static methods in the org.springframework.aop.support.Pointcuts class, or using the ComposablePointcut class in the same package.  
sect2
+ titleRef.   /chapter[1]/sect1[2]/sect2[3]/title[1]
OriginalTraduction
Convenience pointcut implementations  
+ paraRef.   /chapter[1]/sect1[2]/sect2[3]/para[1]
OriginalTraduction
Spring provides several convenient pointcut implementations. Some can be used out of the box; others are intended to be subclassed in application-specific pointcuts.  
+ titleRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[1]/title[1]
OriginalTraduction
Static pointcuts  
+ paraRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[1]/para[1]
OriginalTraduction
Static pointcuts are based on method and target class, and cannot take into account the method's arguments. Static pointcuts are sufficient--and best--for most usages. It's possible for Spring to evaluate a static pointcut only once, when a method is first invoked: after that, there is no need to evaluate the pointcut again with each method invocation.  
+ paraRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[1]/para[2]
OriginalTraduction
Let's consider some static pointcut implementations included with Spring.  
+ titleRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[1]/sect4[1]/title[1]
OriginalTraduction
Regular expression pointcuts  
+ paraRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[1]/sect4[1]/para[1]
OriginalTraduction
One obvious way to specific static pointcuts is regular expressions. Several AOP frameworks besides Spring make this possible. org.springframework.aop.support.RegexpMethodPointcut is a generic regular expression pointcut, using Perl 5 regular expression syntax.  
+ paraRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[1]/sect4[1]/para[2]
OriginalTraduction
Using this class, you can provide a list of pattern Strings. If any of these is a match, the pointcut will evaluate to true. (So the result is effectively the union of these pointcuts.)  
+ paraRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[1]/sect4[1]/para[3]
OriginalTraduction
The usage is shown below:  
+ programlistingRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[1]/sect4[1]/para[4]/programlisting[1]
OriginalTraduction
<bean id="settersAndAbsquatulatePointcut" 
    class="org.springframework.aop.support.RegexpMethodPointcut">
    <property name="patterns">
        <list>
            <value>.*get.*</value>
            <value>.*absquatulate</value>
        </list>
    </property>
</bean>
 
+ paraRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[1]/sect4[1]/para[5]
OriginalTraduction
A convenience subclass of RegexpMethodPointcut, RegexpMethodPointcutAdvisor, allows us to reference an Advice also. (Remember that an Advice can be an interceptor, before advice, throws advice etc.) This simplifies wiring, as the one bean serves as both pointcut and advisor, as shown below:  
+ programlistingRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[1]/sect4[1]/para[6]/programlisting[1]
OriginalTraduction
<bean id="settersAndAbsquatulateAdvisor" 
    class="org.springframework.aop.support.RegexpMethodPointcutAdvisor">
    <property name="advice">
        <ref local="beanNameOfAopAllianceInterceptor"/>
    </property>
    <property name="patterns">
        <list>
            <value>.*get.*</value>
            <value>.*absquatulate</value>
        </list>
    </property>
</bean>
 
+ paraRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[1]/sect4[1]/para[7]
OriginalTraduction
RegexpMethodPointcutAdvisor can be used with any Advice type.  
+ remarkRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[1]/sect4[1]/remark[1]
OriginalTraduction
The RegexpMethodPointcut class requires the Jakarta ORO regular expression package.  
+ titleRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[1]/sect4[2]/title[1]
OriginalTraduction
Attribute-driven pointcuts  
+ paraRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[1]/sect4[2]/para[1]
OriginalTraduction
An important type of static pointcut is a metadata-driven pointcut. This uses the values of metadata attributes: typically, source-level metadata.  
+ titleRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[2]/title[1]
OriginalTraduction
Dynamic pointcuts  
+ paraRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[2]/para[1]
OriginalTraduction
Dynamic pointcuts are costlier to evaluate than static pointcuts. They take into account method arguments, as well as static information. This means that they must be evaluated with every method invocation; the result cannot be cached, as arguments will vary.  
+ paraRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[2]/para[2]
OriginalTraduction
The main example is the control flow pointcut.  
+ titleRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[2]/sect4[1]/title[1]
OriginalTraduction
Control flow pointcuts  
+ paraRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[2]/sect4[1]/para[1]
OriginalTraduction
Spring control flow pointcuts are conceptually similar to AspectJ cflow pointcuts, although less powerful. (There is currently no way to specify that a pointcut executes below another pointcut.) A control flow pointcut matches the current call stack. For example, it might fire if the joinpoint was invoked by a method in the com.mycompany.web package, or by the SomeCaller class. Control flow pointcuts are specified using the org.springframework.aop.support.ControlFlowPointcut class.
+ paraRef.   /chapter[1]/sect1[2]/sect2[3]/sect3[2]/sect4[1]/para[1]/note[1]/para[1]
OriginalTraduction
Control flow pointcuts are significantly more expensive to evaluate at runtime than even other dynamic pointcuts. In Java 1.4, the cost is about 5 times that of other dynamic pointcuts; in Java 1.3 more than 10.  
 
sect2
+ titleRef.   /chapter[1]/sect1[2]/sect2[4]/title[1]
OriginalTraduction
Pointcut superclasses  
+ paraRef.   /chapter[1]/sect1[2]/sect2[4]/para[1]
OriginalTraduction
Spring provides useful pointcut superclasses to help you to implement your own pointcuts.  
+ paraRef.   /chapter[1]/sect1[2]/sect2[4]/para[2]
OriginalTraduction
Because static pointcuts are most useful, you'll probably subclass StaticMethodMatcherPointcut, as shown below. This requires implemented just one abstract method (although it's possible to override other methods to customize behavior):  
+ paraRef.   /chapter[1]/sect1[2]/sect2[4]/para[3]
OriginalTraduction
+ programlistingRef.   /chapter[1]/sect1[2]/sect2[4]/para[3]/programlisting[1]
OriginalTraduction
class TestStaticPointcut extends StaticMethodMatcherPointcut {

    public boolean matches(Method m, Class targetClass) {
        // return true if custom criteria match
    }
}
 
There are also superclasses for dynamic pointcuts.
 
+ paraRef.   /chapter[1]/sect1[2]/sect2[4]/para[4]
OriginalTraduction
You can use custom pointcuts with any advice type in Spring 1.0 RC2 and above.  
sect2
+ titleRef.   /chapter[1]/sect1[2]/sect2[5]/title[1]
OriginalTraduction
Custom pointcuts  
+ paraRef.   /chapter[1]/sect1[2]/sect2[5]/para[1]
OriginalTraduction
Because pointcuts in Spring are Java classes, rather than language features (as in AspectJ) it's possible to declare custom pointcuts, whether static or dynamic. However, there is no support out of the box for the sophisticated pointcut expressions that can be coded in AspectJ syntax. However, custom pointcuts in Spring can be arbitrarily complex.  
+ remarkRef.   /chapter[1]/sect1[2]/sect2[5]/remark[1]
OriginalTraduction
Later versions of Spring may offer support for "semantic pointcuts" as offered by JAC: for example, "all methods that change instance variables in the target object."  
sect1
+ titleRef.   /chapter[1]/sect1[3]/title[1]
OriginalTraduction
Advice types in Spring  
+ paraRef.   /chapter[1]/sect1[3]/para[1]
OriginalTraduction
Let's now look at how Spring AOP handles advice.  
sect2
+ titleRef.   /chapter[1]/sect1[3]/sect2[1]/title[1]
OriginalTraduction
Advice lifecycles  
+ paraRef.   /chapter[1]/sect1[3]/sect2[1]/para[1]
OriginalTraduction
Spring advices can be shared across all advised objects, or unique to each advised object. This corresponds to per-class or per-instance advice.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[1]/para[2]
OriginalTraduction
Per-class advice is used most often. It is appropriate for generic advice such as transaction advisors. These do not depend on the state of the proxied object or add new state; they merely act on the method and arguments.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[1]/para[3]
OriginalTraduction
Per-instance advice is appropriate for introductions, to support mixins. In this case, the advice adds state to the proxied object.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[1]/para[4]
OriginalTraduction
It's possible to use a mix of shared and per-instance advice in the same AOP proxy.  
sect2
+ titleRef.   /chapter[1]/sect1[3]/sect2[2]/title[1]
OriginalTraduction
Advice types in Spring  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/para[1]
OriginalTraduction
Spring provides several advice types out of the box, and is extensible to support arbitrary advice types. Let us look at the basic concepts and standard advice types.  
+ titleRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[1]/title[1]
OriginalTraduction
Interception around advice  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[1]/para[1]
OriginalTraduction
The most fundamental advice type in Spring is interception around advice.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[1]/para[2]
OriginalTraduction
Spring is compliant with the AOP Alliance interface for around advice using method interception. MethodInterceptors implementing around advice should implement the following interface:  
+ programlistingRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[1]/programlisting[1]
OriginalTraduction
public interface MethodInterceptor extends Interceptor {
  
    Object invoke(MethodInvocation invocation) throws Throwable;
}
 
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[1]/para[3]
OriginalTraduction
The MethodInvocation argument to the invoke() method exposes the method being invoked; the target joinpoint; the AOP proxy; and the arguments to the method. The invoke() method should return the invocation's result: the return value of the joinpoint.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[1]/para[4]
OriginalTraduction
A simple MethodInterceptor implementation looks as follows:  
+ programlistingRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[1]/programlisting[2]
OriginalTraduction
public class DebugInterceptor implements MethodInterceptor {

    public Object invoke(MethodInvocation invocation) throws Throwable {
        System.out.println("Before: invocation=[" + invocation + "]");
        Object rval = invocation.proceed();
        System.out.println("Invocation returned");
        return rval;
    }
}
 
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[1]/para[5]
OriginalTraduction
Note the call to the MethodInvocation's proceed() method. This proceeds down the interceptor chain towards the joinpoint. Most interceptors will invoke this method, and return its return value. However, a MethodInterceptor, like any around advice, can return a different value or throw an exception rather than invoke the proceed method. However, you don't want to do this without good reason!  
+ remarkRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[1]/remark[1]
OriginalTraduction
MethodInterceptors offer interoperability with other AOP Alliance-compliant AOP implementations. The other advice types discussed in the remainder of this section implement common AOP concepts, but in a Spring-specific way. While there is an advantage in using the most specific advice type, stick with MethodInterceptor around advice if you are likely to want to run the aspect in another AOP framework. Note that pointcuts are not currently interoperable between frameworks, and the AOP Alliance does not currently define pointcut interfaces.  
+ titleRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[2]/title[1]
OriginalTraduction
Before advice  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[2]/para[1]
OriginalTraduction
A simpler advice type is a before advice. This does not need a MethodInvocation object, since it will only be called before entering the method.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[2]/para[2]
OriginalTraduction
The main advantage of a before advice is that there is no need to invoke the proceed() method, and therefore no possibility of inadvertently failing to proceed down the interceptor chain.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[2]/para[3]
OriginalTraduction
The MethodBeforeAdvice interface is shown below. (Spring's API design would allow for field before advice, although the usual objects apply to field interception and it's unlikely that Spring will ever implement it).  
+ programlistingRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[2]/programlisting[1]
OriginalTraduction
public interface MethodBeforeAdvice extends BeforeAdvice {

    void before(Method m, Object[] args, Object target) throws Throwable;
}
 
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[2]/para[4]
OriginalTraduction
Note the the return type is void. Before advice can insert custom behavior before the joinpoint executes, but cannot change the return value. If a before advice throws an exception, this will abort further execution of the interceptor chain. The exception will propagate back up the interceptor chain. If it is unchecked, or on the signature of the invoked method, it will be passed directly to the client; otherwise it will be wrapped in an unchecked exception by the AOP proxy.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[2]/para[5]
OriginalTraduction
An example of a before advice in Spring, which counts all methods that return normally:  
+ programlistingRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[2]/programlisting[2]
OriginalTraduction
public class CountingBeforeAdvice implements MethodBeforeAdvice {
    private int count;
    public void before(Method m, Object[] args, Object target) throws Throwable {
        ++count;
    }

    public int getCount() { 
        return count; 
    }
}
 
+ remarkRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[2]/remark[1]
OriginalTraduction
Before advice can be used with any pointcut.  
+ titleRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[3]/title[1]
OriginalTraduction
Throws advice  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[3]/para[1]
OriginalTraduction
Throws advice is invoked after the return of the joinpoint if the joinpoint threw an exception. Spring offers typed throws advice. Note that this means that the org.springframework.aop.ThrowsAdvice interface does not contain any methods: it is a tag interface identifying that the given object implements one or more typed throws advice methods. These should be of form  
+ programlistingRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[3]/programlisting[1]
OriginalTraduction
afterThrowing([Method], [args], [target], subclassOfThrowable) 
 
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[3]/para[2]
OriginalTraduction
Only the last argument is required. Thus there from one to four arguments, depending on whether the advice method is interested in the method and arguments. The following are examples of throws advices.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[3]/para[3]
OriginalTraduction
This advice will be invoked if a RemoteException is thrown (including subclasses):  
+ programlistingRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[3]/programlisting[2]
OriginalTraduction
public  class RemoteThrowsAdvice implements ThrowsAdvice {

    public void afterThrowing(RemoteException ex) throws Throwable {
        // Do something with remote exception
    }
}
 
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[3]/para[4]
OriginalTraduction
The following advice is invoked if a ServletException is thrown. Unlike the above advice, it declares 4 arguments, so that it has access to the invoked method, method arguments and target object:  
+ programlistingRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[3]/programlisting[3]
OriginalTraduction
public static class ServletThrowsAdviceWithArguments implements ThrowsAdvice {

    public void afterThrowing(Method m, Object[] args, Object target, ServletException ex) {
        // Do something will all arguments
    }
}
 
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[3]/para[5]
OriginalTraduction
The final example illustrates how these two methods could be used in a single class, which handles both RemoteException and ServletException. Any number of throws advice methods can be combined in a single class.  
+ programlistingRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[3]/programlisting[4]
OriginalTraduction
public static class CombinedThrowsAdvice implements ThrowsAdvice {

    public void afterThrowing(RemoteException ex) throws Throwable {
        // Do something with remote exception
    }
 
    public void afterThrowing(Method m, Object[] args, Object target, ServletException ex) {
        // Do something will all arguments
    }
}
 
+ remarkRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[3]/remark[1]
OriginalTraduction
Throws advice can be used with any pointcut.  
+ titleRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[4]/title[1]
OriginalTraduction
After Returning advice  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[4]/para[1]
OriginalTraduction
An after returning advice in Spring must implement the org.springframework.aop.AfterReturningAdvice interface, shown below:  
+ programlistingRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[4]/programlisting[1]
OriginalTraduction
public interface AfterReturningAdvice extends Advice {

    void afterReturning(Object returnValue, Method m, Object[] args, Object target) 
            throws Throwable;
}
 
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[4]/para[2]
OriginalTraduction
An after returning advice has access to the return value (which it cannot modify), invoked method, methods arguments and target.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[4]/para[3]
OriginalTraduction
The following after returning advice counts all successful method invocations that have not thrown exceptions:  
+ programlistingRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[4]/programlisting[2]
OriginalTraduction
public class CountingAfterReturningAdvice implements AfterReturningAdvice {
    private int count;

    public void afterReturning(Object returnValue, Method m, Object[] args, Object target) throws Throwable {
        ++count;
    }

    public int getCount() {
        return count;
    }
}
 
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[4]/para[4]
OriginalTraduction
This advice doesn't change the execution path. If it throws an exception, this will be thrown up the interceptor chain instead of the return value.  
+ remarkRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[4]/remark[1]
OriginalTraduction
After returning advice can be used with any pointcut.  
+ titleRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/title[1]
OriginalTraduction
Introduction advice  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[1]
OriginalTraduction
Spring treats introduction advice as a special kind of interception advice.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[2]
OriginalTraduction
Introduction requires an IntroductionAdvisor, and an IntroductionInterceptor, implementing the following interface:  
+ programlistingRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/programlisting[1]
OriginalTraduction
public interface IntroductionInterceptor extends MethodInterceptor {

    boolean implementsInterface(Class intf);
}
 
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[3]
OriginalTraduction
The invoke() method inherited from the AOP Alliance MethodInterceptor interface must implement the introduction: that is, if the invoked method is on an introduced interface, the introduction interceptor is responsible for handling the method call--it cannot invoke proceed().  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[4]
OriginalTraduction
Introduction advice cannot be used with any pointcut, as it applies only at class, rather than method, level. You can only use introduction advice with the InterceptionIntroductionAdvisor, which has the following methods:  
+ programlistingRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/programlisting[2]
OriginalTraduction
public interface InterceptionIntroductionAdvisor extends InterceptionAdvisor {

    ClassFilter getClassFilter();

    IntroductionInterceptor getIntroductionInterceptor();

    Class[] getInterfaces();
}
 
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[5]
OriginalTraduction
There is no MethodMatcher, and hence no Pointcut, associated with introduction advice. Only class filtering is logical.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[6]
OriginalTraduction
The getInterfaces() method returns the interfaces introduced by this advisor.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[7]
OriginalTraduction
Let's look at a simple example from the Spring test suite. Let's suppose we want to introduce the following interface to one or more objects:  
+ programlistingRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[8]/programlisting[1]
OriginalTraduction
public interface Lockable {
    void lock();
    void unlock();
    boolean locked();
}
 
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[9]
OriginalTraduction
This illustrates a mixin. We want to be able to cast advised objects to Lockable, whatever their type, and call lock and unlock methods. If we call the lock() method, we want all setter methods to throw a LockedException. Thus we can add an aspect that provides the ability to make objects immutable, without them having any knowledge of it: a good example of AOP.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[10]
OriginalTraduction
Firstly, we'll need an IntroductionInterceptor that does the heavy lifting. In this case, we extend the org.springframework.aop.support.DelegatingIntroductionInterceptor convenience class. We could implement IntroductionInterceptor directly, but using DelegatingIntroductionInterceptor is best for most cases.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[11]
OriginalTraduction
The DelegatingIntroductionInterceptor is designed to delegate an introduction to an actual implementation of the introduced interface(s), concealing the use of interception to do so. The delegate can be set to any object using a constructor argument; the default delegate (when the no-arg constructor is used) is this. Thus in the example below, the delegate is the LockMixin subclass of DelegatingIntroductionInterceptor. Given a delegate (by default itself) a DelegatingIntroductionInterceptor instance looks for all interfaces implemented by the delegate (other than IntroductionInterceptor), and will support introductions against any of them. It's possible for subclasses such as LockMixin to call the suppressInterflace(Class intf) method to suppress interfaces that should not be exposed. However, no matter how many interfaces an IntroductionInterceptor is prepared to support, the IntroductionAdvisor used will control which interfaces are actually exposed. An introduced interface will conceal any implementation of the same interface by the target.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[12]
OriginalTraduction
Thus LockMixin subclasses DelegatingIntroductionInterceptor and implements Lockable itself. The superclass automatically picks up that Lockable can be supported for introduction, so we don't need to specify that. We could introduce any number of interfaces in this way.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[13]
OriginalTraduction
Note the use of the locked instance variable. This effectively adds additional state to that held in the target object.  
+ programlistingRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[14]/programlisting[1]
OriginalTraduction
public class LockMixin extends DelegatingIntroductionInterceptor 
    implements Lockable {

    private boolean locked;

    public void lock() {
        this.locked = true;
    }

    public void unlock() {
        this.locked = false;
    }

    public boolean locked() {
        return this.locked;
    }

    public Object invoke(MethodInvocation invocation) throws Throwable {
        if (locked() && invocation.getMethod().getName().indexOf("set") == 0)
            throw new LockedException();
        return super.invoke(invocation);
    }

}
 
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[15]
OriginalTraduction
Often it isn't necessary to override the invoke() method: the DelegatingIntroductionInterceptor implementation--which calls the delegate method if the method is introduced, otherwise proceeds towards the joinpoint--is usually sufficient. In the present case, we need to add a check: no setter method can be invoked if in locked mode.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[16]
OriginalTraduction
The introduction advisor required is simple. All it needs to do is hold a distinct LockMixin instance, and specify the introduced interfaces--in this case, just Lockable. A more complex example might take a reference to the introduction interceptor (which would be defined as a prototype): in this case, there's no configuration relevant for a LockMixin, so we simply create it using new.  
+ programlistingRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[17]/programlisting[1]
OriginalTraduction
public class LockMixinAdvisor extends DefaultIntroductionAdvisor {

    public LockMixinAdvisor() {
        super(new LockMixin(), Lockable.class);
    }
}
 
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[18]
OriginalTraduction
We can apply this advisor very simply: it requires no configuration. (However, it is necessary: It's impossible to use an IntroductionInterceptor without an IntroductionAdvisor.) As usual with introductions, the advisor must be per-instance, as it is stateful. We need a different instance of LockMixinAdvisor, and hence LockMixin, for each advised object. The advisor comprises part of the advised object's state.  
+ paraRef.   /chapter[1]/sect1[3]/sect2[2]/sect3[5]/para[19]
OriginalTraduction
We can apply this advisor programmatically, using the Advised.addAdvisor() method, or (the recommended way) in XML configuration, like any other advisor. All proxy creation choices discussed below, including "auto proxy creators," correctly handle introductions and stateful mixins.  
sect1
+ titleRef.   /chapter[1]/sect1[4]/title[1]
OriginalTraduction
Advisors in Spring  
+ paraRef.   /chapter[1]/sect1[4]/para[1]
OriginalTraduction
In Spring, an Advisor is a modularization of an aspect. Advisors typically incorporate both an advice and a pointcut.  
+ paraRef.   /chapter[1]/sect1[4]/para[2]
OriginalTraduction
Apart from the special case of introductions, any advisor can be used with any advice. org.springframework.aop.support.DefaultPointcutAdvisor is the most commonly used advisor class. For example, it can be used with a MethodInterceptor, BeforeAdvice or ThrowsAdvice.  
+ paraRef.   /chapter[1]/sect1[4]/para[3]
OriginalTraduction
It is possible to mix advisor and advice types in Spring in the same AOP proxy. For example, you could use a interception around advice, throws advice and before advice in one proxy configuration: Spring will automatically create the necessary create interceptor chain.  
sect1
+ titleRef.   /chapter[1]/sect1[5]/title[1]
OriginalTraduction
Using the ProxyFactoryBean to create AOP proxies  
+ paraRef.   /chapter[1]/sect1[5]/para[1]
OriginalTraduction
If you're using the Spring IoC container (an ApplicationContext or BeanFactory) for your business objects--and you should be!--you will want to use one of Spring's AOP FactoryBeans. (Remember that a factory bean introduces a layer of indirection, enabling it to create objects of a different type).  
+ paraRef.   /chapter[1]/sect1[5]/para[2]
OriginalTraduction
The basic way to create an AOP proxy in Spring is to use the org.springframework.aop.framework.ProxyFactoryBean. This gives complete control over the pointcuts and advice that will apply, and their ordering. However, there are simpler options that are preferable if you don't need such control.  
sect2
+ titleRef.   /chapter[1]/sect1[5]/sect2[1]/title[1]
OriginalTraduction
Basics  
+ paraRef.   /chapter[1]/sect1[5]/sect2[1]/para[1]
OriginalTraduction
The ProxyFactoryBean, like other Spring FactoryBean implementations, introduces a level of indirection. If you define a ProxyFactoryBean with name foo, what objects referencing foo see is not the ProxyFactoryBean instance itself, but an object created by the ProxyFactoryBean's implementation of the getObject() method. This method will create an AOP proxy wrapping a target object.  
+ paraRef.   /chapter[1]/sect1[5]/sect2[1]/para[2]
OriginalTraduction
One of the most important benefits of using a ProxyFactoryBean or other IoC-aware class to create AOP proxies, is that it means that advices and pointcuts can also be managed by IoC. This is a powerful feature, enabling certain approaches that are hard to achieve with other AOP frameworks. For example, an advice may itself reference application objects (besides the target, which should be available in any AOP framework), benefiting from all the pluggability provided by Dependency Injection.  
sect2
+ titleRef.   /chapter[1]/sect1[5]/sect2[2]/title[1]
OriginalTraduction
JavaBean properties  
+ paraRef.   /chapter[1]/sect1[5]/sect2[2]/para[1]
OriginalTraduction
Like most FactoryBean implementations provided with Spring, ProxyFactoryBean is itself a JavaBean. Its properties are used to:  
+ paraRef.   /chapter[1]/sect1[5]/sect2[2]/itemizedlist[1]/listitem[1]/para[1]
OriginalTraduction
Specify the target you want to proxy  
+ paraRef.   /chapter[1]/sect1[5]/sect2[2]/itemizedlist[1]/listitem[2]/para[1]
OriginalTraduction
Specify whether to use CGLIB  
+ paraRef.   /chapter[1]/sect1[5]/sect2[2]/para[2]
OriginalTraduction
Some key properties are inherited from org.springframework.aop.framework.ProxyConfig: the superclass for all AOP proxy factories. These include:  
+ paraRef.   /chapter[1]/sect1[5]/sect2[2]/itemizedlist[2]/listitem[1]/para[1]
OriginalTraduction
proxyTargetClass: true if we should proxy the target class, rather than its interfaces. If this is true we need to use CGLIB.  
+ paraRef.   /chapter[1]/sect1[5]/sect2[2]/itemizedlist[2]/listitem[2]/para[1]
OriginalTraduction
optimize: whether to apply aggressive optimization to created proxies. Don't use this setting unless you understand how the relevant AOP proxy handles optimization. This is currently used only for CGLIB proxies; it has no effect with JDK dynamic proxies (the default).  
+ paraRef.   /chapter[1]/sect1[5]/sect2[2]/itemizedlist[2]/listitem[3]/para[1]
OriginalTraduction
frozen: whether advice changes should be disallowed once the proxy factory has been configured. Default is false.  
+ paraRef.   /chapter[1]/sect1[5]/sect2[2]/itemizedlist[2]/listitem[4]/para[1]
OriginalTraduction
exposeProxy: whether the current proxy should be exposed in a ThreadLocal so that it can be accessed by the target. (It's available via the MethodInvocation without the need for a ThreadLocal.) If a target needs to obtain the proxy and exposeProxy is true, the target can use the AopContext.currentProxy() method.  
+ paraRef.   /chapter[1]/sect1[5]/sect2[2]/itemizedlist[2]/listitem[5]/para[1]
OriginalTraduction
aopProxyFactory: the implementation of AopProxyFactory to use. Offers a way of customizing whether to use dynamic proxies, CGLIB or any other proxy strategy. The default implementation will choose dynamic proxies or CGLIB appropriately. There should be no need to use this property; it's intended to allow the addition of new proxy types in Spring 1.1.  
+ paraRef.   /chapter[1]/sect1[5]/sect2[2]/para[3]
OriginalTraduction
Other properties specific to ProxyFactoryBean include:  
+ paraRef.   /chapter[1]/sect1[5]/sect2[2]/itemizedlist[3]/listitem[1]/para[1]
OriginalTraduction
proxyInterfaces: array of String interface names. If this isn't supplied, a CGLIB proxy for the target class will be used  
+ paraRef.   /chapter[1]/sect1[5]/sect2[2]/itemizedlist[3]/listitem[2]/para[1]
OriginalTraduction
interceptorNames: String array of Advisor, interceptor or other advice names to apply. Ordering is significant. The names are bean names in the current factory, including bean names from ancestor factories.  
+ paraRef.   /chapter[1]/sect1[5]/sect2[2]/itemizedlist[3]/listitem[3]/para[1]
OriginalTraduction
singleton: whether or not the factory should return a single object, no matter how often the getObject() method is called. Several FactoryBean implementations offer such a method. Default value is true. If you want to use stateful advice--for example, for stateful mixins--use prototype advices along with a singleton value of false.  
sect2
+ titleRef.   /chapter[1]/sect1[5]/sect2[3]/title[1]
OriginalTraduction
Proxying interfaces  
+ paraRef.   /chapter[1]/sect1[5]/sect2[3]/para[1]
OriginalTraduction
Let's look at a simple example of ProxyFactoryBean in action. This example involves:  
+ paraRef.   /chapter[1]/sect1[5]/sect2[3]/itemizedlist[1]/listitem[1]/para[1]
OriginalTraduction
A target bean that will be proxied. This is the "personTarget" bean definition in the example below.  
+ paraRef.   /chapter[1]/sect1[5]/sect2[3]/itemizedlist[1]/listitem[2]/para[1]
OriginalTraduction
An Advisor and an Interceptor used to provide advice.  
+ paraRef.   /chapter[1]/sect1[5]/sect2[3]/itemizedlist[1]/listitem[3]/para[1]
OriginalTraduction
An AOP proxy bean definition specifying the target object (the personTarget bean) and the interfaces to proxy, along with the advices to apply.  
+ programlistingRef.   /chapter[1]/sect1[5]/sect2[3]/para[2]/programlisting[1]
OriginalTraduction
<bean id="personTarget" class="com.mycompany.PersonImpl">
    <property name="name"><value>Tony</value></property>
    <property name="age"><value>51</value></property>
</bean>

<bean id="myAdvisor" class="com.mycompany.MyAdvisor">
    <property name="someProperty"><value>Custom string property value</value></property>
</bean>

<bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInterceptor">
</bean>

<bean id="person" 
    class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="proxyInterfaces"><value>com.mycompany.Person</value></property>

    <property name="target"><ref local="personTarget"/></property>
    <property name="interceptorNames">
        <list>
            <value>myAdvisor</value>
            <value>debugInterceptor</value>
        </list>
    </property>
</bean>
 
+ paraRef.   /chapter[1]/sect1[5]/sect2[3]/para[3]
OriginalTraduction
Note that the interceptorNames property takes a list of String: the bean names of the interceptor or advisors in the current factory. Advisors, interceptors, before, after returning and throws advice objects can be used. The ordering of advisors is significant.  
+ remarkRef.   /chapter[1]/sect1[5]/sect2[3]/remark[1]
OriginalTraduction
You might be wondering why the list doesn't hold bean references. The reason for this is that if the ProxyFactoryBean's singleton property is set to false, it must be able to return independent proxy instances. If any of the advisors is itself a prototype, an independent instance would need to be returned, so it's necessary to be able to obtain an instance of the prototype from the factory; holding a reference isn't sufficient.  
+ paraRef.   /chapter[1]/sect1[5]/sect2[3]/para[4]
OriginalTraduction
The "person" bean definition above can be used in place of a Person implementation, as follows:  
+ programlistingRef.   /chapter[1]/sect1[5]/sect2[3]/programlisting[1]
OriginalTraduction
Person person = (Person) factory.getBean("person");
 
+ paraRef.   /chapter[1]/sect1[5]/sect2[3]/para[5]
OriginalTraduction
Other beans in the same IoC context can express a strongly typed dependency on it, as with an ordinary Java object:  
+ programlistingRef.   /chapter[1]/sect1[5]/sect2[3]/para[6]/programlisting[1]
OriginalTraduction
<bean id="personUser" class="com.mycompany.PersonUser">
    <property name="person"><ref local="person" /></property>
</bean>
 
+ paraRef.   /chapter[1]/sect1[5]/sect2[3]/para[7]
OriginalTraduction
The PersonUser class in this example would expose a property of type Person. As far as it's concerned, the AOP proxy can be used transparently in place of a "real" person implementation. However, its class would be a dynamic proxy class. It would be possible to cast it to the Advised interface (discussed below).  
+ paraRef.   /chapter[1]/sect1[5]/sect2[3]/para[8]
OriginalTraduction
It's possible to conceal the distinction between target and proxy using an anonymous inner bean, as follows. Only the ProxyFactoryBean definition is different; the advice is included only for completeness:  
+ programlistingRef.   /chapter[1]/sect1[5]/sect2[3]/para[9]/programlisting[1]
OriginalTraduction
<bean id="myAdvisor" class="com.mycompany.MyAdvisor">
    <property name="someProperty"><value>Custom string property value</value></property>
</bean>

<bean id="debugInterceptor" class="org.springframework.aop.interceptor.DebugInterceptor">
</bean>

<bean id="person" 
    class="org.springframework.aop.framework.ProxyFactoryBean">
    <property name="proxyInterfaces"><value>com.mycompany.Person</value></property>

    <!-- Use inner bean, not local reference to target -->
    <property name="target">
        <bean class="com.mycompany.PersonImpl">
            <property name="name"><value>Tony</value></property>
            <property name="age"><value>51</value></property>
        </bean>
   </property>

    <property name="interceptorNames">
        <list>
            <value>myAdvisor</value>
            <value>debugInterceptor</value>
        </list>
    </property>
</bean>
 
+ paraRef.   /chapter[1]/sect1[5]/sect2[3]/para[10]
OriginalTraduction
This has the advantage that there's only one object of type Person: useful if we want to prevent users of the application context obtaining a reference to the un-advised object, or need to avoid any ambiguity with Spring IoC autowiring. There's also arguably an advantage in that the ProxyFactoryBean definition is self-contained. However, there are times when being able to obtain the un-advised target from the factory might actually be an advantage: for example, in certain test scenarios.  
sect2
+ titleRef.   /chapter[1]/sect1[5]/sect2[4]/title[1]
OriginalTraduction
Proxying classes  
+ paraRef.   /chapter[1]/sect1[5]/sect2[4]/para[1]
OriginalTraduction
What if you need to proxy a class, rather than one or more interfaces?  
+ paraRef.   /chapter[1]/sect1[5]/sect2[4]/para[2]
OriginalTraduction
Imagine that in our example above, there was no Person interface: we needed to advise a class called Person that didn't implement any business interface. In this case, you can configure Spring to use CGLIB proxying, rather than dynamic proxies. Simply set the proxyTargetClass property on the ProxyFactoryBean above to true. While it's best to program to interfaces, rather than classes, the ability to advise classes that don't implement interfaces can be useful when working with legacy code. (In general, Spring isn't prescriptive. While it makes it easy to apply good practices, it avoids forcing a particular approach.)  
+ paraRef.   /chapter[1]/sect1[5]/sect2[4]/para[3]
OriginalTraduction
If you want to you can force the use of CGLIB in any case, even if you do have interfaces.  
+ paraRef.   /chapter[1]/sect1[5]/sect2[4]/para[4]
OriginalTraduction
CGLIB proxying works by generating a subclass of the target class at runtime. Spring configures this generated subclass to delegate method calls to the original target: the subclass is used to implement the Decorator pattern, weaving in the advice.  
+ paraRef.   /chapter[1]/sect1[5]/sect2[4]/para[5]
OriginalTraduction
CGLIB proxying should generally be transparent to users. However, there are some issues to consider:  
+ paraRef.   /chapter[1]/sect1[5]/sect2[4]/itemizedlist[1]/listitem[1]/para[1]
OriginalTraduction
Final methods can't be advised, as they can't be overridden.  
+ paraRef.   /chapter[1]/sect1[5]/sect2[4]/itemizedlist[1]/listitem[2]/para[1]
OriginalTraduction
You'll need the CGLIB 2 binaries on your classpath; dynamic proxies are available with the JDK  
+ paraRef.   /chapter[1]/sect1[5]/sect2[4]/para[6]
OriginalTraduction
There's little performance difference between CGLIB proxying and dynamic proxies. As of Spring 1.0, dynamic proxies are slightly faster. However, this may change in the future. Performance should not be a decisive consideration in this case.  
sect1
+ titleRef.   /chapter[1]/sect1[6]/title[1]
OriginalTraduction
Convenient proxy creation  
+ paraRef.   /chapter[1]/sect1[6]/para[1]
OriginalTraduction
Often we don't need the full power of the ProxyFactoryBean, because we're only interested in one aspect: For example, transaction management.  
+ paraRef.   /chapter[1]/sect1[6]/para[2]
OriginalTraduction
There are a number of convenience factories we can use to create AOP proxies when we want to focus on a specific aspect. These are discussed in other chapters, so we'll just provide a quick survey of some of them here.  
sect2
+ titleRef.   /chapter[1]/sect1[6]/sect2[1]/title[1]
OriginalTraduction
TransactionProxyFactoryBean  
+ paraRef.   /chapter[1]/sect1[6]/sect2[1]/para[1]
OriginalTraduction
The jPetStore sample application shipped with Spring shows the use of the TransactionProxyFactoryBean.  
+ paraRef.   /chapter[1]/sect1[6]/sect2[1]/para[2]
OriginalTraduction
The TransactionProxyFactoryBean is a subclass of ProxyConfig, so basic configuration is shared with ProxyFactoryBean. (See list of ProxyConfig properties above.)  
+ paraRef.   /chapter[1]/sect1[6]/sect2[1]/para[3]
OriginalTraduction
The following example from the jPetStore illustrates how this works. As with a ProxyFactoryBean, there is a target bean definition. Dependencies should be expressed on the proxied factory bean definition ("petStore" here), rather than the target POJO ("petStoreTarget").  
+ paraRef.   /chapter[1]/sect1[6]/sect2[1]/para[4]
OriginalTraduction
The TransactionProxyFactoryBean requires a target, and information about "transaction attributes," specifying which methods should be transactional and the required propagation and other settings:  
+ programlistingRef.   /chapter[1]/sect1[6]/sect2[1]/para[5]/programlisting[1]
OriginalTraduction
<bean id="petStoreTarget" class="org.springframework.samples.jpetstore.domain.logic.PetStoreImpl">
    <property name="accountDao"><ref bean="accountDao"/></property>
    <!-- Other dependencies omitted -->
</bean>

<bean id="petStore" 
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager"><ref bean="transactionManager"/></property>
    <property name="target"><ref local="petStoreTarget"/></property>
    <property name="transactionAttributes">
        <props>
            <prop key="insert*">PROPAGATION_REQUIRED</prop>
            <prop key="update*">PROPAGATION_REQUIRED</prop>
            <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>
        </props>
    </property>
</bean>
 
+ paraRef.   /chapter[1]/sect1[6]/sect2[1]/para[6]
OriginalTraduction
As with the ProxyFactoryBean, we might choose to use an inner bean to set the value of target property, instead of a reference to a top-level target bean.  
+ paraRef.   /chapter[1]/sect1[6]/sect2[1]/para[7]
OriginalTraduction
The TransactionProxyFactoryBean automatically creates a transaction advisor, including a pointcut based on the transaction attributes, so only transactional methods are advised.  
+ paraRef.   /chapter[1]/sect1[6]/sect2[1]/para[8]
OriginalTraduction
The TransactionProxyFactoryBean allows the specification of "pre" and "post" advice, using the preInterceptors and postInterceptors properties. These take Object arrays of interceptors, other advice or Advisors to place in the interception chain before or after the transaction interceptor. These can be populated using a <list> element in XML bean definitions, as follows:  
+ programlistingRef.   /chapter[1]/sect1[6]/sect2[1]/para[9]/programlisting[1]
OriginalTraduction
<property name="preInterceptors">
    <list>
        <ref local="authorizationInterceptor"/>
        <ref local="notificationBeforeAdvice"/>
    </list>
</property>
<property name="postInterceptors">
    <list>
        <ref local="myAdvisor"/>
    </list>
</property>
 
+ paraRef.   /chapter[1]/sect1[6]/sect2[1]/para[10]
OriginalTraduction
These properties could be added to the "petStore" bean definition above. A common usage is to combine transactionality with declarative security: a similar approach to that offered by EJB.  
+ paraRef.   /chapter[1]/sect1[6]/sect2[1]/para[11]
OriginalTraduction
Because of the use of actual instance references, rather than bean names as in ProxyFactoryBean, pre and post interceptors can be used only for shared-instance advice. Thus they are not useful for stateful advice: for example, in mixins. This is consistent with the TransactionProxyFactoryBean's purpose. It provides a simple way of doing common transaction setup. If you need more complex, customized, AOP, consider using the generic ProxyFactoryBean, or an auto proxy creator (see below).  
+ remarkRef.   /chapter[1]/sect1[6]/sect2[1]/remark[1]
OriginalTraduction
Especially if we view Spring AOP as, in many cases, a replacement for EJB, we find that most advice is fairly generic and uses a shared-instance model. Declarative transaction management and security checks are classic examples.  
+ paraRef.   /chapter[1]/sect1[6]/sect2[1]/para[12]
OriginalTraduction
The TransactionProxyFactoryBean depends on a PlatformTransactionManager implementation via its transactionManager JavaBean property. This allows for pluggable transaction implementation, based on JTA, JDBC or other strategies. This relates to the Spring transaction abstraction, rather than AOP. We'll discuss the transaction infrastructure in the next chapter.  
+ remarkRef.   /chapter[1]/sect1[6]/sect2[1]/remark[2]
OriginalTraduction
If you're interested only in declarative transaction management, the TransactionProxyFactoryBean is a good solution, and simpler than using a ProxyFactoryBean.  
sect2
+ titleRef.   /chapter[1]/sect1[6]/sect2[2]/title[1]
OriginalTraduction
EJB proxies  
+ paraRef.   /chapter[1]/sect1[6]/sect2[2]/para[1]
OriginalTraduction
Other dedicated proxies create proxies for EJBs, enabling the EJB "business methods" interface to be used directly by calling code. Calling code does not need to perform JNDI lookups or use EJB create methods: A significant improvement in readability and architectural flexibility.  
+ paraRef.   /chapter[1]/sect1[6]/sect2[2]/para[2]
OriginalTraduction
See the chapter on Spring EJB services in this manual for further information.  
sect1
+ titleRef.   /chapter[1]/sect1[7]/title[1]
OriginalTraduction
Concise proxy definitions  
+ paraRef.   /chapter[1]/sect1[7]/para[1]
OriginalTraduction
Especially when defining transactional proxies, you may end up with many similar proxy definitions. The use of parent and child bean definitions, along with inner bean definitions, can result in much cleaner and more concise proxy definitions.  
+ paraRef.   /chapter[1]/sect1[7]/para[2]
OriginalTraduction
First a parent, template, bean definition is created for the proxy:  
+ programlistingRef.   /chapter[1]/sect1[7]/para[3]/programlisting[1]
OriginalTraduction
<bean id="txProxyTemplate" abstract="true"
        class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
    <property name="transactionManager"><ref local="transactionManager"/></ref></property>
    <property name="transactionAttributes">
      <props>
        <prop key="*">PROPAGATION_REQUIRED</prop>
      </props>
    </property>
</bean>
 
+ paraRef.   /chapter[1]/sect1[7]/para[4]
OriginalTraduction
This will never be instantiated itself, so may actually be incomplete. Then each proxy which needs to be created is just a child bean definition, which to wraps the target of the proxy as an inner bean definition, since the target will never be used on its own anyways.
+ programlistingRef.   /chapter[1]/sect1[7]/para[4]/programlisting[1]
OriginalTraduction
<bean id="myService" parent="txProxyTemplate">
    <property name="target">
      <bean class="org.springframework.samples.MyServiceImpl">
      </bean>
    </property>
</bean>
 
 
+ paraRef.   /chapter[1]/sect1[7]/para[5]
OriginalTraduction
It is of course possible to override properties from the parent template, such as in this case, the transaction propagation settings:
+ programlistingRef.   /chapter[1]/sect1[7]/para[5]/programlisting[1]
OriginalTraduction
<bean id="mySpecialService" parent="txProxyTemplate">
    <property name="target">
      <bean class="org.springframework.samples.MySpecialServiceImpl">
      </bean>
    </property>
    <property name="transactionAttributes">
      <props>
        <prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
        <prop key="find*">PROPAGATION_REQUIRED,readOnly</prop>
        <prop key="load*">PROPAGATION_REQUIRED,readOnly</prop>
        <prop key="store*">PROPAGATION_REQUIRED</prop>
      </props>
    </property>
</bean>
 
 
+ paraRef.   /chapter[1]/sect1[7]/para[6]
OriginalTraduction
Note that in the example above, we have explicitly marked the parent bean definition as abstract by using the abstract attribute, as described previously, so that it may not actually ever be instantiated. Application contexts (but not simple bean factories) will by default pre-instantiate all singletons. Therefore it is important (at least for singleton beans) that if you have a (parent) bean definition which you intend to use only as a template, and this definition specifies a class, you must make sure to set the abstract attribute to true, otherwise the application context will actually try to pre-instantiate it.  
sect1
+ titleRef.   /chapter[1]/sect1[8]/title[1]
OriginalTraduction
Creating AOP proxies programmatically with the ProxyFactory  
+ paraRef.   /chapter[1]/sect1[8]/para[1]
OriginalTraduction
It's easy to create AOP proxies programmatically using Spring. This enables you to use Spring AOP without dependency on Spring IoC.  
+ paraRef.   /chapter[1]/sect1[8]/para[2]
OriginalTraduction
The following listing shows creation of a proxy for a target object, with one interceptor and one advisor. The interfaces implemented by the target object will automatically be proxied:  
+ programlistingRef.   /chapter[1]/sect1[8]/para[3]/programlisting[1]
OriginalTraduction
ProxyFactory factory = new ProxyFactory(myBusinessInterfaceImpl);
factory.addInterceptor(myMethodInterceptor);
factory.addAdvisor(myAdvisor);
MyBusinessInterface tb = (MyBusinessInterface) factory.getProxy();
 
+ paraRef.   /chapter[1]/sect1[8]/para[4]
OriginalTraduction
The first step is to construct a object of type org.springframework.aop.framework.ProxyFactory. You can create this with a target object, as in the above example, or specify the interfaces to be proxied in an alternate constructor.  
+ paraRef.   /chapter[1]/sect1[8]/para[5]
OriginalTraduction
You can add interceptors or advisors, and manipulate them for the life of the ProxyFactory. If you add an IntroductionInterceptionAroundAdvisor you can cause the proxy to implement additional interfaces.  
+ paraRef.   /chapter[1]/sect1[8]/para[6]
OriginalTraduction
There are also convenience methods on ProxyFactory (inherited from AdvisedSupport) allowing you to add other advice types such as before and throws advice. AdvisedSupport is the superclass of both ProxyFactory and ProxyFactoryBean.  
+ remarkRef.   /chapter[1]/sect1[8]/remark[1]
OriginalTraduction
Integrating AOP proxy creation with the IoC framework is best practice in most applications. We recommend that you externalize configuration from Java code with AOP, as in general.  
sect1
+ titleRef.   /chapter[1]/sect1[9]/title[1]
OriginalTraduction
Manipulating advised objects  
+ paraRef.   /chapter[1]/sect1[9]/para[1]
OriginalTraduction
However you create AOP proxies, you can manipulate them using the org.springframework.aop.framework.Advised interface. Any AOP proxy can be cast to this interface, whatever other interfaces it implements. This interface includes the following methods:  
+ programlistingRef.   /chapter[1]/sect1[9]/programlisting[1]
OriginalTraduction
Advisor[] getAdvisors();

void addAdvice(Advice advice) throws AopConfigException;

void addAdvice(int pos, Advice advice) 
        throws AopConfigException;

void addAdvisor(Advisor advisor) throws AopConfigException;

void addAdvisor(int pos, Advisor advisor) throws AopConfigException;

int indexOf(Advisor advisor);

boolean removeAdvisor(Advisor advisor) throws AopConfigException;

void removeAdvisor(int index) throws AopConfigException;

boolean replaceAdvisor(Advisor a, Advisor b) throws AopConfigException;

boolean isFrozen();
 
+ paraRef.   /chapter[1]/sect1[9]/para[2]
OriginalTraduction
The getAdvisors() method will return an Advisor for every advisor, interceptor or other advice type that has been added to the factory. If you added an Advisor, the returned advisor at this index will be the object that you added. If you added an interceptor or other advice type, Spring will have wrapped this in an advisor with a pointcut that always returns true. Thus if you added a MethodInterceptor, the advisor returned for this index will be an DefaultPointcutAdvisor returning your MethodInterceptor and a pointcut that matches all classes and methods.  
+ paraRef.   /chapter[1]/sect1[9]/para[3]
OriginalTraduction
The addAdvisor() methods can be used to add any Advisor. Usually the advisor holding pointcut and advice will be the generic DefaultPointcutAdvisor, which can be used with any advice or pointcut (but not for introduction).  
+ paraRef.   /chapter[1]/sect1[9]/para[4]
OriginalTraduction
By default, it's possible to add or remove advisors or interceptors even once a proxy has been created. The only restriction is that it's impossible to add or remove an introduction advisor, as existing proxies from the factory will not show the interface change. (You can obtain a new proxy from the factory to avoid this problem.)  
+ paraRef.   /chapter[1]/sect1[9]/para[5]
OriginalTraduction
A simple example of casting an AOP proxy to the Advised interface and examining and manipulating its advice:  
+ programlistingRef.   /chapter[1]/sect1[9]/para[6]/programlisting[1]
OriginalTraduction
Advised advised = (Advised) myObject;
Advisor[] advisors = advised.getAdvisors();
int oldAdvisorCount = advisors.length;
System.out.println(oldAdvisorCount + " advisors");

// Add an advice like an interceptor without a pointcut
// Will match all proxied methods
// Can use for interceptors, before, after returning or throws advice
advised.addAdvice(new DebugInterceptor());

// Add selective advice using a pointcut
advised.addAdvisor(new DefaultPointcutAdvisor(mySpecialPointcut, myAdvice));

assertEquals("Added two advisors",
     oldAdvisorCount + 2, advised.getAdvisors().length);
 
+ remarkRef.   /chapter[1]/sect1[9]/remark[1]
OriginalTraduction
It's questionable whether it's advisable (no pun intended) to modify advice on a business object in production, although there are no doubt legitimate usage cases. However, it can be very useful in development: for example, in tests. I have sometimes found it very useful to be able to add test code in the form of an interceptor or other advice, getting inside a method invocation I want to test. (For example, the advice can get inside a transaction created for that method: for example, to run SQL to check that a database was correctly updated, before marking the transaction for roll back.)  
+ paraRef.   /chapter[1]/sect1[9]/para[7]
OriginalTraduction
Depending on how you created the proxy, you can usually set a frozen flag, in which case the Advised isFrozen() method will return true, and any attempts to modify advice through addition or removal will result in an AopConfigException. The ability to freeze the state of an advised object is useful in some cases: For example, to prevent calling code removing a security interceptor. It may also be used in Spring 1.1 to allow aggressive optimization if runtime advice modification is known not to be required.  
sect1
+ titleRef.   /chapter[1]/sect1[10]/title[1]
OriginalTraduction
Using the "autoproxy" facility  
+ paraRef.   /chapter[1]/sect1[10]/para[1]
OriginalTraduction
So far we've considered explicit creation of AOP proxies using a ProxyFactoryBean or similar factory bean.  
+ paraRef.   /chapter[1]/sect1[10]/para[2]
OriginalTraduction
Spring also allows us to use "autoproxy" bean definitions, which can automatically proxy selected bean definitions. This is built on Spring "bean post processor" infrastructure, which enables modification of any bean definition as the container loads.  
+ paraRef.   /chapter[1]/sect1[10]/para[3]
OriginalTraduction
In this model, you set up some special bean definitions in your XML bean definition file configuring the auto proxy infrastructure. This allows you just to declare the targets eligible for autoproxying: you don't need to use ProxyFactoryBean.  
+ paraRef.   /chapter[1]/sect1[10]/para[4]
OriginalTraduction
There are two ways to do this:  
+ paraRef.   /chapter[1]/sect1[10]/itemizedlist[1]/listitem[1]/para[1]
OriginalTraduction
Using an autoproxy creator that refers to specific beans in the current context  
+ paraRef.   /chapter[1]/sect1[10]/itemizedlist[1]/listitem[2]/para[1]
OriginalTraduction
A special case of autoproxy creation that deserves to be considered separately; autoproxy creation driven by source-level metadata attributes  
sect2
+ titleRef.   /chapter[1]/sect1[10]/sect2[1]/title[1]
OriginalTraduction
Autoproxy bean definitions  
+ paraRef.   /chapter[1]/sect1[10]/sect2[1]/para[1]
OriginalTraduction
The org.springframework.aop.framework.autoproxy package provides the following standard autoproxy creators.  
+ titleRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[1]/title[1]
OriginalTraduction
BeanNameAutoProxyCreator  
+ paraRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[1]/para[1]
OriginalTraduction
The BeanNameAutoProxyCreator automatically creates AOP proxies for beans with names matching literal values or wildcards.  
+ programlistingRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[1]/para[2]/programlisting[1]
OriginalTraduction
<bean id="jdkBeanNameProxyCreator" 
    class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    <property name="beanNames"><value>jdk*,onlyJdk</value></property>
    <property name="interceptorNames">
        <list>
            <value>myInterceptor</value>
        </list>
    </property>
</bean>
 
+ paraRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[1]/para[3]
OriginalTraduction
As with ProxyFactoryBean, there is an interceptorNames property rather than a list of interceptor, to allow correct behavior for prototype advisors. Named "interceptors" can be advisors or any advice type.  
+ paraRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[1]/para[4]
OriginalTraduction
As with auto proxying in general, the main point of using BeanNameAutoProxyCreator is to apply the same configuration consistently to multiple objects, and with minimal volume of configuration. It is a popular choice for applying declarative transactions to multiple objects.  
+ paraRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[1]/para[5]
OriginalTraduction
Bean definitions whose names match, such as "jdkMyBean" and "onlyJdk" in the above example, are plain old bean definitions with the target class. An AOP proxy will be created automatically by the BeanNameAutoProxyCreator. The same advice will be applied to all matching beans. Note that if advisors are used (rather than the interceptor in the above example), the pointcuts may apply differently to different beans.  
+ titleRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[2]/title[1]
OriginalTraduction
DefaultAdvisorAutoProxyCreator  
+ paraRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[2]/para[1]
OriginalTraduction
A more general and extremely powerful auto proxy creator is DefaultAdvisorAutoProxyCreator. This will automagically apply eligible advisors in the current context, without the need to include specific bean names in the autoproxy advisor's bean definition. It offers the same merit of consistent configuration and avoidance of duplication as BeanNameAutoProxyCreator.  
+ paraRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[2]/para[2]
OriginalTraduction
Using this mechanism involves:  
+ paraRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[2]/itemizedlist[1]/listitem[1]/para[1]
OriginalTraduction
Specifying a DefaultAdvisorAutoProxyCreator bean definition  
+ paraRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[2]/itemizedlist[1]/listitem[2]/para[1]
OriginalTraduction
Specifying any number of Advisors in the same or related contexts. Note that these must be Advisors, not just interceptors or other advices. This is necessary because there must be a pointcut to evaluate, to check the eligibility of each advice to candidate bean definitions.  
+ paraRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[2]/para[3]
OriginalTraduction
The DefaultAdvisorAutoProxyCreator will automatically evaluate the pointcut contained in each advisor, to see what (if any) advice it should apply to each business object (such as "businessObject1" and "businessObject2" in the example).  
+ paraRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[2]/para[4]
OriginalTraduction
This means that any number of advisors can be applied automatically to each business object. If no pointcut in any of the advisors matches any method in a business object, the object will not be proxied. As bean definitions are added for new business objects, they will automatically be proxied if necessary.  
+ paraRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[2]/para[5]
OriginalTraduction
Autoproxying in general has the advantage of making it impossible for callers or dependencies to obtain an un-advised object. Calling getBean("businessObject1") on this ApplicationContext will return an AOP proxy, not the target business object. (The "inner bean" idiom shown earlier also offers this benefit.)  
+ programlistingRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[2]/para[6]/programlisting[1]
OriginalTraduction
<bean id="autoProxyCreator"
    class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
</bean>

<bean id="txAdvisor"
    autowire="constructor"
    class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor">
    <property name="order"><value>1</value></property>
</bean>

<bean id="customAdvisor"
    class="com.mycompany.MyAdvisor">
</bean>

<bean id="businessObject1"
    class="com.mycompany.BusinessObject1">
    <!-- Properties omitted -->
</bean>

<bean id="businessObject2"
    class="com.mycompany.BusinessObject2">
</bean>
 
+ paraRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[2]/para[7]
OriginalTraduction
The DefaultAdvisorAutoProxyCreator is very useful if you want to apply the same advice consistently to many business objects. Once the infrastructure definitions are in place, you can simply add new business objects without including specific proxy configuration. You can also drop in additional aspects very easily--for example, tracing or performance monitoring aspects--with minimal change to configuration.  
+ paraRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[2]/para[8]
OriginalTraduction
The DefaultAdvisorAutoProxyCreator offers support for filtering (using a naming convention so that only certain advisors are evaluated, allowing use of multiple, differently configured, AdvisorAutoProxyCreators in the same factory) and ordering. Advisors can implement the org.springframework.core.Ordered interface to ensure correct ordering if this is an issue. The TransactionAttributeSourceAdvisor used in the above example has a configurable order value; default is unordered.  
+ titleRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[3]/title[1]
OriginalTraduction
AbstractAdvisorAutoProxyCreator  
+ paraRef.   /chapter[1]/sect1[10]/sect2[1]/sect3[3]/para[1]
OriginalTraduction
This is the superclass of DefaultAdvisorAutoProxyCreator. You can create your own autoproxy creators by subclassing this class, in the unlikely event that advisor definitions offer insufficient customization to the behavior of the framework DefaultAdvisorAutoProxyCreator.  
sect2
+ titleRef.   /chapter[1]/sect1[10]/sect2[2]/title[1]
OriginalTraduction
Using metadata-driven auto-proxying  
+ paraRef.   /chapter[1]/sect1[10]/sect2[2]/para[1]
OriginalTraduction
A particularly important type of autoproxying is driven by metadata. This produces a similar programming model to .NET ServicedComponents. Instead of using XML deployment descriptors as in EJB, configuration for transaction management and other enterprise services is held in source-level attributes.  
+ paraRef.   /chapter[1]/sect1[10]/sect2[2]/para[2]
OriginalTraduction
In this case, you use the DefaultAdvisorAutoProxyCreator, in combination with Advisors that understand metadata attributes. The metadata specifics are held in the pointcut part of the candidate advisors, rather than in the autoproxy creation class itself.  
+ paraRef.   /chapter[1]/sect1[10]/sect2[2]/para[3]
OriginalTraduction
This is really a special case of the DefaultAdvisorAutoProxyCreator, but deserves consideration on its own. (The metadata-aware code is in the pointcuts contained in the advisors, not the AOP framework itself.)  
+ paraRef.   /chapter[1]/sect1[10]/sect2[2]/para[4]
OriginalTraduction
The /attributes directory of the jPetStore sample application shows the use of attribute-driven autoproxying. In this case, there's no need to use the TransactionProxyFactoryBean. Simply defining transactional attributes on business objects is sufficient, because of the use of metadata-aware pointcuts. The bean definitions include the following code, in /WEB-INF/declarativeServices.xml. Note that this is generic, and can be used outside the jPetStore:  
+ programlistingRef.   /chapter[1]/sect1[10]/sect2[2]/para[5]/programlisting[1]
OriginalTraduction
<bean id="autoProxyCreator" 
    class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator">
</bean>

<bean id="transactionAttributeSource"
    class="org.springframework.transaction.interceptor.AttributesTransactionAttributeSource"
    autowire="constructor">
</bean>

<bean id="transactionInterceptor"
    class="org.springframework.transaction.interceptor.TransactionInterceptor"
    autowire="byType">
</bean>

<bean id="transactionAdvisor"
    class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"
    autowire="constructor" >
</bean>

<bean id="attributes"
    class="org.springframework.metadata.commons.CommonsAttributes"
/>
 
+ paraRef.   /chapter[1]/sect1[10]/sect2[2]/para[6]
OriginalTraduction
The DefaultAdvisorAutoProxyCreator bean definition--called "autoProxyCreator" in this case, but the name is not significant (it could even be omitted)--will pick up all eligible pointcuts in the current application context. In this case, the "transactionAdvisor" bean definition, of type TransactionAttributeSourceAdvisor, will apply to classes or methods carrying a transaction attribute. The TransactionAttributeSourceAdvisor depends on a TransactionInterceptor, via constructor dependency. The example resolves this via autowiring. The AttributesTransactionAttributeSource depends on an implementation of the org.springframework.metadata.Attributes interface. In this fragment, the "attributes" bean satisfies this, using the Jakarta Commons Attributes API to obtain attribute information. (The application code must have been compiled using the Commons Attributes compilation task.)  
+ paraRef.   /chapter[1]/sect1[10]/sect2[2]/para[7]
OriginalTraduction
The TransactionInterceptor defined here depends on a PlatformTransactionManager definition, which is not included in this generic file (although it could be) because it will be specific to the application's transaction requirements (typically JTA, as in this example, or Hibernate, JDO or JDBC):  
+ programlistingRef.   /chapter[1]/sect1[10]/sect2[2]/programlisting[1]
OriginalTraduction
<bean id="transactionManager" 
    class="org.springframework.transaction.jta.JtaTransactionManager"/>
 
+ remarkRef.   /chapter[1]/sect1[10]/sect2[2]/remark[1]
OriginalTraduction
If you require only declarative transaction management, using these generic XML definitions will result in Spring automatically proxying all classes or methods with transaction attributes. You won't need to work directly with AOP, and the programming model is similar to that of .NET ServicedComponents.  
+ paraRef.   /chapter[1]/sect1[10]/sect2[2]/para[8]
OriginalTraduction
This mechanism is extensible. It's possible to do autoproxying based on custom attributes. You need to:  
+ paraRef.   /chapter[1]/sect1[10]/sect2[2]/itemizedlist[1]/listitem[1]/para[1]
OriginalTraduction
Define your custom attribute.  
+ paraRef.   /chapter[1]/sect1[10]/sect2[2]/itemizedlist[1]/listitem[2]/para[1]
OriginalTraduction
Specify an Advisor with the necessary advice, including a pointcut that is triggered by the presence of the custom attribute on a class or method. You may be able to use an existing advice, merely implementing a static pointcut that picks up the custom attribute.  
+ paraRef.   /chapter[1]/sect1[10]/sect2[2]/para[9]
OriginalTraduction
It's possible for such advisors to be unique to each advised class (for example, mixins): they simply need to be defined as prototype, rather than singleton, bean definitions. For example, the LockMixin introduction interceptor from the Spring test suite, shown above, could be used in conjunction with an attribute-driven pointcut to target a mixin, as shown here. We use the generic DefaultPointcutAdvisor, configured using JavaBean properties:  
+ programlistingRef.   /chapter[1]/sect1[10]/sect2[2]/para[10]/programlisting[1]
OriginalTraduction
<bean id="lockMixin"
    class="org.springframework.aop.LockMixin"
    singleton="false"
/>

<bean id="lockableAdvisor"
    class="org.springframework.aop.support.DefaultPointcutAdvisor"
    singleton="false"
>
    <property name="pointcut">
        <ref local="myAttributeAwarePointcut"/>
    </property>
    <property name="advice">
        <ref local="lockMixin"/>
    </property>
</bean>

<bean id="anyBean" class="anyclass" ...
 
+ paraRef.   /chapter[1]/sect1[10]/sect2[2]/para[11]
OriginalTraduction
If the attribute aware pointcut matches any methods in the anyBean or other bean definitions, the mixin will be applied. Note that both lockMixin and lockableAdvisor definitions are prototypes. The myAttributeAwarePointcut pointcut can be a singleton definition, as it doesn't hold state for individual advised objects.  
sect1
+ titleRef.   /chapter[1]/sect1[11]/title[1]
OriginalTraduction
Using TargetSources  
+ paraRef.   /chapter[1]/sect1[11]/para[1]
OriginalTraduction
Spring offers the concept of a TargetSource, expressed in the org.springframework.aop.TargetSource interface. This interface is responsible for returning the "target object" implementing the joinpoint. The TargetSource implementation is asked for a target instance each time the AOP proxy handles a method invocation.  
+ paraRef.   /chapter[1]/sect1[11]/para[2]
OriginalTraduction
Developers using Spring AOP don't normally need to work directly with TargetSources, but this provides a powerful means of supporting pooling, hot swappable and other sophisticated targets. For example, a pooling TargetSource can return a different target instance for each invocation, using a pool to manage instances.  
+ paraRef.   /chapter[1]/sect1[11]/para[3]
OriginalTraduction
If you do not specify a TargetSource, a default implementation is used that wraps a local object. The same target is returned for each invocation (as you would expect).  
+ paraRef.   /chapter[1]/sect1[11]/para[4]
OriginalTraduction
Let's look at the standard target sources provided with Spring, and how you can use them.  
+ remarkRef.   /chapter[1]/sect1[11]/remark[1]
OriginalTraduction
When using a custom target source, your target will usually need to be a prototype rather than a singleton bean definition. This allows Spring to create a new target instance when required.  
sect2
+ titleRef.   /chapter[1]/sect1[11]/sect2[1]/title[1]
OriginalTraduction
Hot swappable target sources  
+ paraRef.   /chapter[1]/sect1[11]/sect2[1]/para[1]
OriginalTraduction
The org.springframework.aop.target.HotSwappableTargetSource exists to allow the target of an AOP proxy to be switched while allowing callers to keep their references to it.  
+ paraRef.   /chapter[1]/sect1[11]/sect2[1]/para[2]
OriginalTraduction
Changing the target source's target takes effect immediately. The HotSwappableTargetSource is threadsafe.  
+ paraRef.   /chapter[1]/sect1[11]/sect2[1]/para[3]
OriginalTraduction
You can change the target via the swap() method on HotSwappableTargetSource as follows:  
+ programlistingRef.   /chapter[1]/sect1[11]/sect2[1]/para[4]/programlisting[1]
OriginalTraduction
HotSwappableTargetSource swapper = 
    (HotSwappableTargetSource) beanFactory.getBean("swapper");
Object oldTarget = swapper.swap(newTarget);
 
+ paraRef.   /chapter[1]/sect1[11]/sect2[1]/para[5]
OriginalTraduction
The XML definitions required look as follows:  
+ programlistingRef.   /chapter[1]/sect1[11]/sect2[1]/para[6]/programlisting[1]
OriginalTraduction
<bean id="initialTarget" class="mycompany.OldTarget">
</bean>

<bean id="swapper" 
    class="org.springframework.aop.target.HotSwappableTargetSource">
    <constructor-arg><ref local="initialTarget"/></constructor-arg>
</bean>

<bean id="swappable" 
    class="org.springframework.aop.framework.ProxyFactoryBean"
>
    <property name="targetSource">
        <ref local="swapper"/>
    </property>
</bean>
 
+ paraRef.   /chapter[1]/sect1[11]/sect2[1]/para[7]
OriginalTraduction
The above swap() call changes the target of the swappable bean. Clients who hold a reference to that bean will be unaware of the change, but will immediately start hitting the new target.  
+ paraRef.   /chapter[1]/sect1[11]/sect2[1]/para[8]
OriginalTraduction
Although this example doesn't add any advice--and it's not necessary to add advice to use a TargetSource--of course any TargetSource can be used in conjunction with arbitrary advice.  
sect2
+ titleRef.   /chapter[1]/sect1[11]/sect2[2]/title[1]
OriginalTraduction
Pooling target sources  
+ paraRef.   /chapter[1]/sect1[11]/sect2[2]/para[1]
OriginalTraduction
Using a pooling target source provides a similar programming model to stateless session EJBs, in which a pool of identical instances is maintained, with method invocations going to free objects in the pool.  
+ paraRef.   /chapter[1]/sect1[11]/sect2[2]/para[2]
OriginalTraduction
A crucial difference between Spring pooling and SLSB pooling is that Spring pooling can be applied to any POJO. As with Spring in general, this service can be applied in a non-invasive way.  
+ paraRef.   /chapter[1]/sect1[11]/sect2[2]/para[3]
OriginalTraduction
Spring provides out-of-the-box support for Jakarta Commons Pool 1.1, which provides a fairly efficient pooling implementation. You'll need the commons-pool Jar on your application's classpath to use this feature. It's also possible to subclass org.springframework.aop.target.AbstractPoolingTargetSource to support any other pooling API.  
+ paraRef.   /chapter[1]/sect1[11]/sect2[2]/para[4]
OriginalTraduction
Sample configuration is shown below:  
+ programlistingRef.   /chapter[1]/sect1[11]/sect2[2]/para[5]/programlisting[1]
OriginalTraduction
<bean id="businessObjectTarget" class="com.mycompany.MyBusinessObject" 
    singleton="false">
    ... properties omitted
</bean>

<bean id="poolTargetSource" 
    class="org.springframework.aop.target.CommonsPoolTargetSource">
    <property name="targetBeanName"><value>businessObjectTarget</value></property>
    <property name="maxSize"><value>25</value></property>
</bean>

<bean id="businessObject" 
    class="org.springframework.aop.framework.ProxyFactoryBean"
>
    <property name="targetSource"><ref local="poolTargetSource"/></property>
    <property name="interceptorNames"><value>myInterceptor</value></property>
</bean>
 
+ paraRef.   /chapter[1]/sect1[11]/sect2[2]/para[6]
OriginalTraduction
Note that the target object--"businessObjectTarget" in the example--must be a prototype. This allows the PoolingTargetSource implementation to create new instances of the target to grow the pool as necessary. See the Javadoc for AbstractPoolingTargetSource and the concrete subclass you wish to use for information about it's properties: maxSize is the most basic, and always guaranteed to be present.  
+ paraRef.   /chapter[1]/sect1[11]/sect2[2]/para[7]
OriginalTraduction
In this case, "myInterceptor" is the name of an interceptor that would need to be defined in the same IoC context. However, it isn't necessary to specify interceptors to use pooling. If you want only pooling, and no other advice, don't set the interceptorNames property at all.  
+ paraRef.   /chapter[1]/sect1[11]/sect2[2]/para[8]
OriginalTraduction
It's possible to configure Spring so as to be able to cast any pooled object to the org.springframework.aop.target.PoolingConfig interface, which exposes information about the configuration and current size of the pool through an introduction. You'll need to define an advisor like this:  
+ programlistingRef.   /chapter[1]/sect1[11]/sect2[2]/para[9]/programlisting[1]
OriginalTraduction
<bean id="poolConfigAdvisor" 
    class="org.springframework.beans.factory.config.MethodInvokingFactoryBean">
    <property name="targetObject"><ref local="poolTargetSource" /></property>
    <property name="targetMethod"><value>getPoolingConfigMixin</value></property>
</bean>
 
+ paraRef.   /chapter[1]/sect1[11]/sect2[2]/para[10]
OriginalTraduction
This advisor is obtained by calling a convenience method on the AbstractPoolingTargetSource class, hence the use of MethodInvokingFactoryBean. This advisor's name ("poolConfigAdvisor" here) must be in the list of interceptors names in the ProxyFactoryBean exposing the pooled object.  
+ paraRef.   /chapter[1]/sect1[11]/sect2[2]/para[11]
OriginalTraduction
The cast will look as follows:  
+ programlistingRef.   /chapter[1]/sect1[11]/sect2[2]/para[12]/programlisting[1]
OriginalTraduction
PoolingConfig conf = (PoolingConfig) beanFactory.getBean("businessObject");
System.out.println("Max pool size is " + conf.getMaxSize());
 
+ remarkRef.   /chapter[1]/sect1[11]/sect2[2]/remark[1]
OriginalTraduction
Pooling stateless service objects is not usually necessary. We don't believe it should be the default choice, as most stateless objects are naturally thread safe, and instance pooling is problematic if resources are cached.  
+ paraRef.   /chapter[1]/sect1[11]/sect2[2]/para[13]
OriginalTraduction
Simpler pooling is available using autoproxying. It's possible to set the TargetSources used by any autoproxy creator.  
sect2
+ titleRef.   /chapter[1]/sect1[11]/sect2[3]/title[1]
OriginalTraduction
Prototype" target sources  
+ paraRef.   /chapter[1]/sect1[11]/sect2[3]/para[1]
OriginalTraduction
Setting up a "prototype" target source is similar to a pooling TargetSource. In this case, a new instance of the target will be created on every method invocation. Although the cost of creating a new object isn't high in a modern JVM, the cost of wiring up the new object (satisfying its IoC dependencies) may be more expensive. Thus you shouldn't use this approach without very good reason.  
+ paraRef.   /chapter[1]/sect1[11]/sect2[3]/para[2]
OriginalTraduction
To do this, you could modify the poolTargetSource definition shown above as follows. (I've also changed the name, for clarity.)  
+ programlistingRef.   /chapter[1]/sect1[11]/sect2[3]/para[3]/programlisting[1]
OriginalTraduction
<bean id="prototypeTargetSource" 
    class="org.springframework.aop.target.PrototypeTargetSource">
    <property name="targetBeanName"><value>businessObjectTarget</value></property>
</bean>
 
+ paraRef.   /chapter[1]/sect1[11]/sect2[3]/para[4]
OriginalTraduction
There's only one property: the name of the target bean. Inheritance is used in the TargetSource implementations to ensure consistent naming. As with the pooling target source, the target bean must be a prototype bean definition.  
sect1
+ titleRef.   /chapter[1]/sect1[12]/title[1]
OriginalTraduction
Defining new Advice types  
+ paraRef.   /chapter[1]/sect1[12]/para[1]
OriginalTraduction
Spring AOP is designed to be extensible. While the interception implementation strategy is presently used internally, it is possible to support arbitrary advice types in addition to interception around advice, before, throws advice and after returning advice, which are supported out of the box.  
+ paraRef.   /chapter[1]/sect1[12]/para[2]
OriginalTraduction
The org.springframework.aop.framework.adapter package is an SPI package allowing support for new custom advice types to be added without changing the core framework. The only constraint on a custom Advice type is that it must implement the org.aopalliance.aop.Advice tag interface.  
+ paraRef.   /chapter[1]/sect1[12]/para[3]
OriginalTraduction
Please refer to the org.springframework.aop.framework.adapter package's Javadocs for further information  
sect1
+ titleRef.   /chapter[1]/sect1[13]/title[1]
OriginalTraduction
Further reading and resources  
+ paraRef.   /chapter[1]/sect1[13]/para[1]
OriginalTraduction
I recommend the excellent AspectJ in Action by Ramnivas Laddad (Manning, 2003) for an introduction to AOP.  
+ paraRef.   /chapter[1]/sect1[13]/para[2]
OriginalTraduction
Please refer to the Spring sample applications for further examples of Spring AOP:  
+ paraRef.   /chapter[1]/sect1[13]/itemizedlist[1]/listitem[1]/para[1]
OriginalTraduction
The JPetStore's default configuration illustrates the use of the TransactionProxyFactoryBean for declarative transaction management  
+ paraRef.   /chapter[1]/sect1[13]/itemizedlist[1]/listitem[2]/para[1]
OriginalTraduction
The /attributes directory of the JPetStore illustrates the use of attribute-driven declarative transaction management  
+ paraRef.   /chapter[1]/sect1[13]/para[3]
OriginalTraduction
If you are interested in more advanced capabilities of Spring AOP, take a look at the test suite. The test coverage is over 90%, and this illustrates advanced features not discussed in this document.  
sect1
+ titleRef.   /chapter[1]/sect1[14]/title[1]
OriginalTraduction
Roadmap  
+ paraRef.   /chapter[1]/sect1[14]/para[1]
OriginalTraduction
Spring AOP, like the rest of Spring, is actively developed. The core API is stable. Like the rest of Spring, the AOP framework is very modular, enabling extension while preserving the fundamental design. Several improvements are planned in the Spring 1.1 time frame, which will preserve backward compatibility. These include:  
+ paraRef.   /chapter[1]/sect1[14]/itemizedlist[1]/listitem[1]/para[1]
OriginalTraduction
Performance improvements: The creation of AOP proxies is handled by a factory via a Strategy interface. Thus we can support additional AopProxy types without impacting user code or the core implementation. Significant performance optimizations for CGLIB proxying are scheduled for the 1.0.3 release, with further optimizations by Spring 1.1 in cases where advice will not change at runtime. This should produce a significant reduction in the overhead of the AOP framework. Note, however, that the overhead of the AOP framework is not an issue in normal usage.  
+ paraRef.   /chapter[1]/sect1[14]/itemizedlist[1]/listitem[2]/para[1]
OriginalTraduction
More expressive pointcuts: Spring presently offers an expressive Pointcut interface, but we can add value through adding more Pointcut implementations. We are looking at an integration with AspectJ that will allow AspectJ pointcut expressions to be used in Spring configuration files. And if you wish to contribute a useful Pointcut, please do!  
+ paraRef.   /chapter[1]/sect1[14]/para[2]
OriginalTraduction
The most significant enhancements are likely to concern integration with AspectJ, which will be done in cooperation with the AspectJ community. We believe that this will provide significant benefits for both Spring and AspectJ users, in the following areas:  
+ paraRef.   /chapter[1]/sect1[14]/itemizedlist[2]/listitem[1]/para[1]
OriginalTraduction
Allowing AspectJ aspects to be configured using Spring IoC. This has the potential to integrate AspectJ aspects into applications where appropriate, in the same way as Spring aspects are integrated into application IoC contexts.  
+ paraRef.   /chapter[1]/sect1[14]/itemizedlist[2]/listitem[2]/para[1]
OriginalTraduction
Allowing the use of AspectJ pointcut expressions within Spring configuration to target Spring advice. This has significant benefits over devising our own pointcut expression language; AspectJ is both well thought out and well documented.  
+ paraRef.   /chapter[1]/sect1[14]/para[3]
OriginalTraduction
Both these integrations should be available in Spring 1.1.  


Index des chapitres