我需要攔截org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter#處理方法,我使用spring aop。它是spring-webmvc.jar的spring類。它在org.springframework.web.servlet.DispatcherServlet中的請求過程中用於我的rest mvc服務。如何使用彈簧aop從外部jar的類
AOP配置:
<bean id="contextAspect" class="com.eightbitlab.spring3rest.config.ContextAspect"/>
<aop:aspectj-autoproxy proxy-target-class="true"/>
<aop:config>
<aop:aspect ref="contextAspect">
<aop:pointcut id="contextPointcut" expression="execution (* org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handle(..))"/>
<aop:around method="around" pointcut-ref="contextPointcut"/>
</aop:aspect>
</aop:config>
看點豆:
@Aspect
public class ContextAspect {
public void around(ProceedingJoinPoint joinPoint) throws Throwable {
Logger.getAnonymousLogger().info("start aspect");
Object proceeded = joinPoint.proceed();
Logger.getAnonymousLogger().info("end aspect");
}
}
如果我用自己的類執行方面的方法這方面。我認爲這個問題是一個來自外部jar的類,但我找不到解決方案...
感謝您的信息。但是從接口「處理」的方法,我認爲如果我會使用動態代理而不是CGI它會工作,但是當我添加 - 沒有改變( –
miroshnik
在切入點你已明確提到建議'RequestMappingHandlerAdapter.handle'的執行已將其標記爲'final',所以不管代理類型如何,它都不起作用 –
即使切入點更新爲「target」(org.springframework.web.servlet .HandlerAdapter),Spring運行時將會選擇'RequestMappingHandlerAdapter',因爲它是通過'@ RequestMapping'配置的映射的查詢處理程序。除非你有特別的理由堅持建議'handle'方法IMO嘗試通知控制器。 –