This article describes the usage of AspectJ in a Spring project. AspectJ has advantages opposite to Spring AOP. In Spring AOP your beans have to be proxied. Furthermore Spring AOP is limited to method interception. Spring AOP doesn't have any field-access or object creation.
AspectJ in a Java Spring project provides much more flexibility. The core message is AspectJ will be necessary if you need more AOP accessibility.
Following example runs inside of Spring application context. If you want to use AspectJ primarily you have to add the aop namespace in your application context file.
<beans ... xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="... http://www.springframework.org/schema/aop/spring-aop-2.0.xsd ..."> ... </beans>After that your configures your aspects in Spring injection style.
<bean id="loggerAspect" class="org.developers.blog.aspect.example.LoggerAspect"/> <aop:config proxy-target-class="true"> <aop:aspect id="logger" ref="loggerAspect"> <aop:around pointcut="execution(* org.developers..*.*(..))" method="log"/> </aop:aspect> </aop:config>The Aspect is realized as a standard Java class with AOP annotations. In this example this aspect will run if all methods under org.developers package are called.
@Aspect
public class LoggerAspect {
@Around("execution(* org.developers.blog..*.*(..))")
public Object log(ProceedingJoinPoint pjp) throws Throwable {
String classMethodIdentifier = pjp.getTarget().getClass().getSimpleName() + "." + pjp.getSignature().getName();
System.out.println(classMethodIdentifier + " - called" );
Object retVal = pjp.proceed();
System.out.println(classMethodIdentifier + " - finished" );
return retVal;
}
}
Regards,Rafael Sobek
Technorati Tags: AspectJ Spring Java AOP Config

Be careful. You should use either the <aop:xxxx> tags OR the annotations. You don't need both. In your example, the annotations are being ignored (you must include <aop:aspect:autoproxy/> in your context to enable that).
In both cases, you are still using Spring AOP (albeit with @AspectJ annotations) and not AspectJ itself.