Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/spring-mvc/2.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Spring mvc 如何在Spring拦截器预处理方法中获取控制器方法名_Spring Mvc_Annotations_Interceptor - Fatal编程技术网

Spring mvc 如何在Spring拦截器预处理方法中获取控制器方法名

Spring mvc 如何在Spring拦截器预处理方法中获取控制器方法名,spring-mvc,annotations,interceptor,Spring Mvc,Annotations,Interceptor,在基于SpringMVC和SpringSecurity的应用程序中,我使用@Controller注释来配置控制器 我已经配置了Spring处理程序拦截器,在preHandle()方法中,我想获得拦截器将调用的方法名 我想在HandlerInterceptor的preHandle()method中的controller方法上定义自定义注释,以便我可以通过记录该特定方法的活动来管理 请看一下我的申请要求和代码 @Controller public class ConsoleUserManagemen

在基于SpringMVC和SpringSecurity的应用程序中,我使用
@Controller
注释来配置控制器

我已经配置了Spring处理程序拦截器,在
preHandle()
方法中,我想获得拦截器将调用的方法名

我想在
HandlerInterceptor
preHandle()
method中的controller方法上定义自定义注释,以便我可以通过记录该特定方法的活动来管理

请看一下我的申请要求和代码

@Controller
public class ConsoleUserManagementController{
@RequestMapping(value = CONSOLE_NAMESPACE + "/account/changePassword.do", method = RequestMethod.GET)
@doLog(true)
public ModelAndView showChangePasswordPage() {
    String returnView = USERMANAGEMENT_NAMESPACE + "/account/ChangePassword";
    ModelAndView mavChangePassword = new ModelAndView(returnView);
    LogUtils.logInfo("Getting Change Password service prerequisit attributes");
    mavChangePassword.getModelMap().put("passwordModel", new PasswordModel());
    return mavChangePassword;
}
}


我在我的应用程序中使用Spring3.0,我不知道处理程序拦截器,但您可以尝试使用Aspects,为所有控制器方法创建一个通用拦截器

通过使用方面,可以很容易地访问joinpoint方法名称

您可以将请求对象注入到方面中,也可以使用:

HttpServletRequest request = ((ServletRequestAttributes)RequestContextHolder.getRequestAttributes()).getRequest();
从您的advice方法检索它

例如:

@Around("execution (* com.yourpackages.controllers.*.*(..)) && @annotation(org.springframework.web.bind.annotation.RequestMapping)")
public Object doSomething(ProceedingJoinPoint pjp){
 pjp.getSignature().getDeclaringType().getName();
}

谢谢Bob,但如果第一个处理程序拦截器没有帮助的话,我想试试它。然后我可以决定实现方面,是的,Bob,最后我用Aspect@Vinicius卡瓦略-如果我真的不想使用方面,你得到解决方案了吗?你检查过用下面的方法吗?
@Around("execution (* com.yourpackages.controllers.*.*(..)) && @annotation(org.springframework.web.bind.annotation.RequestMapping)")
public Object doSomething(ProceedingJoinPoint pjp){
 pjp.getSignature().getDeclaringType().getName();
}