how to get controller method name in Spring Interceptor preHandle method

后端 未结 1 1057
被撕碎了的回忆
被撕碎了的回忆 2021-01-20 09:54

In my application based on spring mvc and spring security I am using @Controller annotation to configure controller.

I have configured Spring Ha

相关标签:
1条回答
  • 2021-01-20 10:42

    Don't know about the Handler interceptor, but you could try to use Aspects and create a general interceptor for all your controller methods.

    Using aspects, it would be easy to access your joinpoint method name.

    You can inject the request object inside your aspect or use:

    HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
    

    To retrieve it from your advice method.

    For instance:

    @Around("execution (* com.yourpackages.controllers.*.*(..)) && @annotation(org.springframework.web.bind.annotation.RequestMapping)")
    public Object doSomething(ProceedingJoinPoint pjp){
     pjp.getSignature().getDeclaringType().getName();
    }
    
    0 讨论(0)
提交回复
热议问题