1 package de.spring.example;
3 import org.aspectj.lang.annotation.AfterReturning;
4 import org.aspectj.lang.annotation.Aspect;
5 import org.aspectj.lang.annotation.Pointcut;
9 * We are using here the @AspectJ annotations to declare
10 * Proxies. If we want to use these kinds of proxies on the Spring framework
11 * we have to use the <aop:aspectj-autoproxy/> annotation on the Spring xml file
12 * (the Spring context file)
15 public class SystemArchitecture {
17 //Coonecting to the execution of any method defined in the
18 //package: de.spring.example.web
19 //We are connecting the methods defined in that package with this
20 //Pointcut. So, when executing any of those methods defined in that
21 //package we will run the Advice related to this Pointcut (if there is an Advice)
22 @Pointcut("execution(* de.spring.example.web.*.*(..))")
23 public void pointCutMethod()
25 System.out.println("I am the Pointcut and you will never see me.");
26 //This is the PointCut.
27 //You can write code here, but it will be useless because while running
28 //the methods connected to the Pointcut, this code will not be executed.
29 //Just the advice will run!!!! :/
30 //Is not this weird? We are here defining a method whose code
31 //will never be run. When the hell should we write code here?
32 //This is a waste of time and code IMHO. Isn't it?
35 //NOTICE: YOU DO NOT NEED TO CREATE A SPECIAL CLASS FOR THE ADVICE
36 // YOU COULD USE THE SAME CLASS FOR THE POINTCUTS AND FOR THE
37 // ADVICES. IN THIS CASE FOR EXAMPLE WE HAVE THE @AfterReturning
38 // ADVICE IN THIS CLASS AND THE @Before ADVICE IN THE CLASS CALLED
40 //This advice is connected with the another Pointcut.
41 //The returning value of every method connected to that Pointcut
42 //will be caught by this method.
43 @AfterReturning(pointcut="de.spring.example.SystemArchitecture.pointCutMethod())",
45 public void doAccessCheck(final Object retVal) {
46 System.out.println("The returned value by the method " +
47 "connected to the Pointcut: " + retVal);