Spring FrameworkAspectJ Integration

Traducteur:  Thierry TEMPLIER
(Dernière date de traduction:  02/01/2005)
Relecteur:  
(Dernière date de relecture:  )
Index des chapitres

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

chapter
+ titleRef.   /chapter[1]/translation[1]
OriginalTraduction
AspectJ IntegrationIntégration d'AspectJ
sect1
+ titleRef.   /chapter[1]/sect1[1]/translation[1]
OriginalTraduction
OverviewVue d'ensemble
+ paraRef.   /chapter[1]/sect1[1]/translation[2]
OriginalTraduction
Spring's proxy-based AOP framework is well suited for handling many generic middleware and application-specific problems. However, there are times when a more powerful AOP solution is required: for example, if we need to add additional fields to a class, or advise fine-grained objects that aren't created by the Spring IoC container.Le framework AOP de Spring basé sur les proxies est bien adapté pour résoudre beaucoup des problèmes génériques des middlewares et spécifiques des applications. Cependant, il arrive qu'une solution AOP plus puissante soit requise: par exemple, si des champs supplémentaires doivent être ajoutés à une classe, ou si des advices d'une granularité plus fines ne peuvent pas être créés avec le conteneur IoC de Spring.
+ paraRef.   /chapter[1]/sect1[1]/translation[3]
OriginalTraduction
We recommend the use of AspectJ in such cases. Accordingly, as of version 1.1, Spring provides a powerful integration with AspectJ.Nous recommendons l'utilisation d'AspectJ dans ces cas précis puisque dans sa version 1.1, Spring offre une puissante intégration avec AspectJ.
sect1
+ titleRef.   /chapter[1]/sect1[2]/translation[1]
OriginalTraduction
Configuring AspectJ aspects using Spring IoCConfiguration des aspects d'AspectJ en utilisant le conteneur IoC de Spring
+ paraRef.   /chapter[1]/sect1[2]/para[1]
OriginalTraduction
The most important part of the Spring/AspectJ integration allows Spring to configure AspectJ aspects using Dependency Injection. This brings similar benefits to aspects as to objects. For example:  
+ paraRef.   /chapter[1]/sect1[2]/itemizedlist[1]/listitem[1]/para[1]
OriginalTraduction
There is no need for aspects to use ad hoc configuration mechanisms; they can be configured in the same, consistent, approach used for the entire application.  
+ paraRef.   /chapter[1]/sect1[2]/itemizedlist[1]/listitem[2]/para[1]
OriginalTraduction
Aspects can depend on application objects. For example, a security aspect can depend on a security manager, as we'll see in an example shortly.  
+ paraRef.   /chapter[1]/sect1[2]/itemizedlist[1]/listitem[3]/para[1]
OriginalTraduction
It's possible to obtain a reference to an aspect through the relevant Spring context. This can allow for dynamic reconfiguration of the aspect.  
+ paraRef.   /chapter[1]/sect1[2]/para[2]
OriginalTraduction
AspectJ aspects can expose JavaBean properties for Setter Injection, and even implement Spring lifecycle interfaces such as BeanFactoryAware.  
+ remarkRef.   /chapter[1]/sect1[2]/remark[1]
OriginalTraduction
Note that AspectJ aspects cannot use Constructor Injection or Method Injection. This limitation is due to the fact that aspects do not have constructors that can be invoked like constructors of objects.  
sect2
+ titleRef.   /chapter[1]/sect1[2]/sect2[1]/title[1]
OriginalTraduction
"Singleton" aspects  
+ paraRef.   /chapter[1]/sect1[2]/sect2[1]/para[1]
OriginalTraduction
In most cases, AspectJ aspects are singletons, with one instance per class loader. This single instance is responsible for advising multiple object instances.  
+ paraRef.   /chapter[1]/sect1[2]/sect2[1]/para[2]
OriginalTraduction
A Spring IoC container cannot instantiate an aspect, as aspects don't have callable constructors. But it can obtain a reference to an aspect using the static aspectOf() method that AspectJ defines for all aspects, and it can inject dependencies into that aspect.  
+ titleRef.   /chapter[1]/sect1[2]/sect2[1]/sect3[1]/title[1]
OriginalTraduction
Example  
+ paraRef.   /chapter[1]/sect1[2]/sect2[1]/sect3[1]/para[1]
OriginalTraduction
Consider a security aspect, which depends on a security manager. This aspects applies to all changes in the value of the balance instance variable in the Account class. (We couldn't do this in the same way using Spring AOP.)  
+ paraRef.   /chapter[1]/sect1[2]/sect2[1]/sect3[1]/para[2]
OriginalTraduction
The AspectJ code for the aspect (one of the Spring/AspectJ samples), is shown below. Note that the dependency on the SecurityManager interface is expressed in a JavaBean property:  
+ programlistingRef.   /chapter[1]/sect1[2]/sect2[1]/sect3[1]/para[3]/programlisting[1]
OriginalTraduction
public aspect BalanceChangeSecurityAspect {

   private SecurityManager securityManager;

   public void setSecurityManager(SecurityManager securityManager) {
      this.securityManager = securityManager;
   }

   private pointcut balanceChanged() : 
      set(int Account.balance);

   before() : balanceChanged() {
      this.securityManager.checkAuthorizedToModify();
   }
}
 
+ paraRef.   /chapter[1]/sect1[2]/sect2[1]/sect3[1]/para[4]
OriginalTraduction
We configure this aspect in the same way as an ordinary class. Note that the way in which we set the property reference is identical. Note that we must use the factory-method attribute to specify that we want the aspect "created" using the aspectOf() static method. In fact, this is locating, rather than, creating, the aspect, but the Spring container doesn't care:  
+ programlistingRef.   /chapter[1]/sect1[2]/sect2[1]/sect3[1]/para[5]/programlisting[1]
OriginalTraduction
<bean id="securityAspect" 
   class="org.springframework.samples.aspectj.bank.BalanceChangeSecurityAspect" 
   factory-method="aspectOf"
>
   <property name="securityManager">
      <ref local="securityManager"/>
   </property>
</bean>
 
+ paraRef.   /chapter[1]/sect1[2]/sect2[1]/sect3[1]/para[6]
OriginalTraduction
We don't need to do anything in Spring configuration to target this aspect. It contains the pointcut information in AspectJ code that controls where it applies. Thus it can apply even to objects not managed by the Spring IoC container.  
+ titleRef.   /chapter[1]/sect1[2]/sect2[1]/sect3[2]/title[1]
OriginalTraduction
Ordering issues  
+ paraRef.   /chapter[1]/sect1[2]/sect2[1]/sect3[2]/para[1]
OriginalTraduction
to be completed  
sect2
+ titleRef.   /chapter[1]/sect1[2]/sect2[2]/title[1]
OriginalTraduction
Non-singleton aspects  
+ paraRef.   /chapter[1]/sect1[2]/sect2[2]/para[1]
OriginalTraduction
** Complete material on pertarget etc.  
sect2
+ titleRef.   /chapter[1]/sect1[2]/sect2[3]/title[1]
OriginalTraduction
Gotchas  
+ paraRef.   /chapter[1]/sect1[2]/sect2[3]/para[1]
OriginalTraduction
to be completed  
+ paraRef.   /chapter[1]/sect1[2]/sect2[3]/para[2]
OriginalTraduction
- Singleton issue  
sect1
+ titleRef.   /chapter[1]/sect1[3]/title[1]
OriginalTraduction
Using AspectJ pointcuts to target Spring advice  
+ paraRef.   /chapter[1]/sect1[3]/para[1]
OriginalTraduction
In a future release of Spring, we plan to provide the ability for AspectJ pointcut expressions to be used in Spring XML or other bean definition files, to target Spring advice. This will allow some of the power of the AspectJ pointcut model to be applied to Spring's proxy-based AOP framework. This will work in pure Java, and will not require the AspectJ compiler. Only the subset of AspectJ pointcuts relating to method invocation will be usable.  
+ paraRef.   /chapter[1]/sect1[3]/para[2]
OriginalTraduction
This feature is scheduled for Spring 1.2. It depends on AspectJ enhancements.  
+ paraRef.   /chapter[1]/sect1[3]/para[3]
OriginalTraduction
This feature replaces our previous plan to create a pointcut expression language for Spring.  
sect1
+ titleRef.   /chapter[1]/sect1[4]/title[1]
OriginalTraduction
Spring aspects for AspectJ  
+ paraRef.   /chapter[1]/sect1[4]/para[1]
OriginalTraduction
In a future release of Spring (probably 1.2), we will package some Spring services, such as the declarative transaction management service, as AspectJ aspects. This will enable them to be used by AspectJ users without dependence on the Spring AOP framework--potentially, even without dependence on the Spring IoC container.  
+ paraRef.   /chapter[1]/sect1[4]/para[2]
OriginalTraduction
This feature is probably of more interest to AspectJ users than Spring users.  


Index des chapitres