| | + title | Ref. /chapter[1]/translation[1] |
| Original | Traduction | AspectJ Integration | Intégration d'AspectJ | sect1
| | + title | Ref. /chapter[1]/sect1[1]/translation[1] |
| Original | Traduction | Overview | Vue d'ensemble |
| + para | Ref. /chapter[1]/sect1[1]/translation[2] |
| Original | Traduction | 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. |
| + para | Ref. /chapter[1]/sect1[1]/translation[3] |
| Original | Traduction | 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
| | + title | Ref. /chapter[1]/sect1[2]/translation[1] |
| Original | Traduction | Configuring AspectJ aspects using Spring IoC | Configuration des aspects d'AspectJ en utilisant le conteneur IoC de Spring |
| + para | Ref. /chapter[1]/sect1[2]/para[1] |
| Original | Traduction | 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: |
|
| + para | Ref. /chapter[1]/sect1[2]/itemizedlist[1]/listitem[1]/para[1] |
| Original | Traduction | 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. |
|
| + para | Ref. /chapter[1]/sect1[2]/itemizedlist[1]/listitem[2]/para[1] |
| Original | Traduction | 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. |
|
| + para | Ref. /chapter[1]/sect1[2]/itemizedlist[1]/listitem[3]/para[1] |
| Original | Traduction | It's possible to obtain a reference to an aspect through the
relevant Spring context. This can allow for dynamic reconfiguration of
the aspect. |
|
| + para | Ref. /chapter[1]/sect1[2]/para[2] |
| Original | Traduction | AspectJ aspects can expose JavaBean properties for Setter Injection,
and even implement Spring lifecycle interfaces such as BeanFactoryAware. |
|
| + remark | Ref. /chapter[1]/sect1[2]/remark[1] |
| Original | Traduction | 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
| | + title | Ref. /chapter[1]/sect1[2]/sect2[1]/title[1] |
| Original | Traduction | "Singleton" aspects |
|
| + para | Ref. /chapter[1]/sect1[2]/sect2[1]/para[1] |
| Original | Traduction | In most cases, AspectJ aspects are singletons, with one instance
per class loader. This single instance is responsible for advising
multiple object instances. |
|
| + para | Ref. /chapter[1]/sect1[2]/sect2[1]/para[2] |
| Original | Traduction | 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. |
|
| + title | Ref. /chapter[1]/sect1[2]/sect2[1]/sect3[1]/title[1] |
| Original | Traduction | Example |
|
| + para | Ref. /chapter[1]/sect1[2]/sect2[1]/sect3[1]/para[1] |
| Original | Traduction | 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.) |
|
| + para | Ref. /chapter[1]/sect1[2]/sect2[1]/sect3[1]/para[2] |
| Original | Traduction | 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: |
|
| + programlisting | Ref. /chapter[1]/sect1[2]/sect2[1]/sect3[1]/para[3]/programlisting[1] |
| Original | Traduction | 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();
}
} |
|
| + para | Ref. /chapter[1]/sect1[2]/sect2[1]/sect3[1]/para[4] |
| Original | Traduction | 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: |
|
| + programlisting | Ref. /chapter[1]/sect1[2]/sect2[1]/sect3[1]/para[5]/programlisting[1] |
| Original | Traduction | <bean id="securityAspect"
class="org.springframework.samples.aspectj.bank.BalanceChangeSecurityAspect"
factory-method="aspectOf"
>
<property name="securityManager">
<ref local="securityManager"/>
</property>
</bean> |
|
| + para | Ref. /chapter[1]/sect1[2]/sect2[1]/sect3[1]/para[6] |
| Original | Traduction | 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. |
|
| + title | Ref. /chapter[1]/sect1[2]/sect2[1]/sect3[2]/title[1] |
| Original | Traduction | Ordering issues |
|
| + para | Ref. /chapter[1]/sect1[2]/sect2[1]/sect3[2]/para[1] |
| Original | Traduction | to be completed |
|
| | sect2
| | + title | Ref. /chapter[1]/sect1[2]/sect2[2]/title[1] |
| Original | Traduction | Non-singleton aspects |
|
| + para | Ref. /chapter[1]/sect1[2]/sect2[2]/para[1] |
| Original | Traduction | ** Complete material on pertarget etc. |
|
| | sect2
| | + title | Ref. /chapter[1]/sect1[2]/sect2[3]/title[1] |
| Original | Traduction | Gotchas |
|
| + para | Ref. /chapter[1]/sect1[2]/sect2[3]/para[1] |
| Original | Traduction | to be completed |
|
| + para | Ref. /chapter[1]/sect1[2]/sect2[3]/para[2] |
| Original | Traduction | - Singleton issue |
|
| |
| | sect1
| | + title | Ref. /chapter[1]/sect1[3]/title[1] |
| Original | Traduction | Using AspectJ pointcuts to target Spring advice |
|
| + para | Ref. /chapter[1]/sect1[3]/para[1] |
| Original | Traduction | 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. |
|
| + para | Ref. /chapter[1]/sect1[3]/para[2] |
| Original | Traduction | This feature is scheduled for Spring 1.2. It depends on AspectJ
enhancements. |
|
| + para | Ref. /chapter[1]/sect1[3]/para[3] |
| Original | Traduction | This feature replaces our previous plan to create a pointcut
expression language for Spring. |
|
| | sect1
| | + title | Ref. /chapter[1]/sect1[4]/title[1] |
| Original | Traduction | Spring aspects for AspectJ |
|
| + para | Ref. /chapter[1]/sect1[4]/para[1] |
| Original | Traduction | 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. |
|
| + para | Ref. /chapter[1]/sect1[4]/para[2] |
| Original | Traduction | This feature is probably of more interest to AspectJ users than
Spring users. |
|
| |
|