Note that there are some explanatory texts on larger screens.

plurals
  1. POSpring HandlerMethodArgumentResolver not executing
    primarykey
    data
    text
    <p>I am using Spring MVC 3.2.2</p> <p>I have defined a custom HandlerMethodArgumentResolver class like this</p> <pre><code>public class CurrentUserArgumentResolver implements HandlerMethodArgumentResolver { public CurrentUserArgumentResolver() { System.out.println("Ready"); } @Override public boolean supportsParameter(MethodParameter parameter) { return parameter.hasParameterAnnotation(CurrentUser.class); } @Override public Object resolveArgument(MethodParameter parameter, ModelAndViewContainer mavContainer, NativeWebRequest webRequest, WebDataBinderFactory binderFactory) throws Exception { Principal principal = webRequest.getUserPrincipal(); System.out.println("*** Principal ***: " + principal); return principal; } } </code></pre> <p>And added the following to my app-servlet.xml</p> <pre><code>&lt;mvc:annotation-driven&gt; &lt;mvc:argument-resolvers&gt; &lt;beans:bean class="my.package.CurrentUserArgumentResolver" lazy-init="false"/&gt; &lt;/mvc:argument-resolvers&gt; &lt;/mvc:annotation-driven&gt; </code></pre> <p>and created an annotation for CurrentUser</p> <pre><code>@Target(ElementType.PARAMETER) @Retention(RetentionPolicy.RUNTIME) public @interface CurrentUser { } </code></pre> <p>When I start the application up the class is constructed as I can see the log message "Ready" but the resolver does not execute when I annotate a controller method as such (in a class that has @Controller annotation)</p> <pre><code>@RequestMapping(method = RequestMethod.POST, value = "/update") public ModelAndView update(@RequestParam MultipartFile background, @CurrentUser Principal principal) { ... } </code></pre> <p>If I put breakpoints on either method in the CurrentUserArgumentResolver class, neither work. So not sure what I am missing?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload