Spring point point for all methods in the controller

I want to run some code before each method in Spring (3.2.3) @Controller. I have the following definition, but it will not work. I suspect that the pointcut expression is incorrect.

dispatcher-servlet.xml

<aop:aspectj-autoproxy/> <bean class="com.example.web.controllers.ThingAspect"/> 

cewcThingAspect

 @Pointcut("execution(com.example.web.controllers.ThingController.*(..))") public void thing() { } @Before("thing()") public void doStuffBeforeThing(JoinPoint joinPoint) { // do stuff here } 
+6
source share
3 answers

The pointcut expression does not have a return type, such as void , String or * , for example

 execution(* com.example.web.controllers.ThingController.*(..)) 
+5
source

The correct way to do this in current versions of Spring MVC is through the ControllerAdvice .
See: Advising controllers with @ControllerAdvice annotation

For previous versions, refer to my answer: fooobar.com/questions/471812 / ...

+7
source

Besides the @ControllerAdvice , which was already mentioned in another answer, you should check Spring MVC interceptors .

They basically simplify AOP for controllers and can be used in cases where @ControllerAdvice does not give you enough power.

+2
source

All Articles