Spring HandlerMethodArgumentResolver not executing

后端 未结 3 645
自闭症患者
自闭症患者 2020-12-10 14:53

I am using Spring MVC 3.2.2

I have defined a custom HandlerMethodArgumentResolver class like this

public class CurrentUserArgumentResolver implements         


        
3条回答
  •  温柔的废话
    2020-12-10 15:25

    OK I worked out that Spring was already resolving the Principal object in my above example and so my argument resolver was not kicking in. I had been lazy and added the @CurrentUser annotation to an existing parameter.

    So I changed my example

    @RequestMapping(method = RequestMethod.POST, value = "/update")
    public ModelAndView update(@RequestParam MultipartFile background, @CurrentUser Principal principal) {
      ...
    }
    

    to use my User model class

    @RequestMapping(method = RequestMethod.POST, value = "/update")
    public ModelAndView update(@RequestParam MultipartFile background, @CurrentUser User user) {
      ...
    }
    

    and now it works!

提交回复
热议问题