Episode 8. What's your Aspect?

Published: Nov. 17, 2011, 9 p.m.

b'

In this episode we go over Aspects (and AspectJ), what really is, and when to use them. It turns out, that there is nothing misterious about them! We also cover how to set-up Aspects for J2SE so you can start using them immediately!

\\n

Questions, feedback or comments! comments@javapubhouse.com

\\n

VM Parameter
-javaagent:dep/aspectjweaver.jar

\\n

Example Aspect

\\n
@Aspect

public class OrderAspect {

@Before("execution(* *.*(Order))") // must qualify
public void anyCall() {
System.out.println("Was called from anywhere");
}
}

\\n

Example aop.xml file

\\n
          







\\n

Example Folder Structure

\\n
src
|
|-META-INF
|
|-aop.xml
\\n

References:

\\n

http://www.eclipse.org/aspectj/doc/released/adk15notebook/ataspectj-pcadvice.html

\\n

http://www.eclipse.org/aspectj/doc/next/quick5.pdf

\\n

http://blog.espenberntsen.net/2010/03/20/aspectj-cheat-sheet/

\\n

(Using aspects with annotations)
http://stackoverflow.com/questions/2011089/aspectj-pointcut-for-all-methods-of-a-class-with-specific-annotation

'