AspectJ Integration

AspectJ aspects can be configured and used as a bean. Since aspects are no regular bean in the sense that they provide a static factory method "aspectOf" to obtain aspect instances, a special tag <aspectj> is provided to symplify the configuration of aspects.

This tag is not pre-loaded as the standard tags. In order to use it, <nut> tag is used to load it.

For example:

<module name="test aspectj">
<!--load the aspectj tag -->
<nut name="aspectj" class="jfun.yan.xml.nuts.optional.AspectjNut"/>
<body>
  <bean id="datasource" .../>
  <aspectj class="com.mycompany.SomeAspect" props="{datasource=$datasource}"/>
  ...
</body>
</module>

It is of course possible to use the <bean> tag directly to configure aspects, just the same way as what we do in Spring:

<method id="someaspect" class="com.mycompany.SomeAspect" name="aspectOf"/>
<bean props="{datasource=$datasource}" eager-init="true" component="$someaspect"/>

Different from Spring, Nuts does not do eager initialization by default. Therefore, we need to explicitly set the "eager-init" attribute in order to make sure the aspect is initialized properly before the advice is applied.

Compared to the <aspectj> tag, the latter way is just more verbose.

Labels

 
(None)