Spring (3.2.3) @Controller의 모든 메소드 앞에 일부 코드를 실행하고 싶습니다. 다음 정의 된 있지만 실행되지 않습니다. pointcut 표현이 올바르지 않은 것 같습니다.컨트롤러의 모든 메소드에 대한 Spring AOP 포인트 컷
디스패처-servlet.xml에
<aop:aspectj-autoproxy/>
<bean class="com.example.web.controllers.ThingAspect"/>
c.e.w.c.ThingAspect
@Pointcut("execution(com.example.web.controllers.ThingController.*(..))")
public void thing() {
}
@Before("thing()")
public void doStuffBeforeThing(JoinPoint joinPoint) {
// do stuff here
}
어쩌면 ['@ ControllerAdvice'] (http://docs.spring.io/spring/docs/4.0.3.RELEASE/javadoc-api/org/springframework/web/bind/annotation/ControllerAdvice .html) 당신이 찾고있는 것입니다. –
(a) 전혀 실행되지 않거나 (b) 일부 메소드에서 실행되지 않습니까? 이렇게하면 문제를 진단하는 데 도움이됩니다. – Phil
ControllerAdvice는 존재하지 않았지만 ExceptHandler, InitBinder 및 ModelAttribute를 여러 컨트롤러에 연결하기위한 설명서를 보았습니다. 필자는 모든 경우에 RequestMapping 주석이 달린 메소드가 있기 전에 실행할 메소드를 찾고있었습니다. 현재 Aspect는 어떤 방법으로도 호출되지 않습니다. 나는 Spring Interceptor를 사용할 수 있었지만 AOP는 작업에 이상적으로 보였다. – Goose