RedirectAttributes throwing IllegalStateException in Spring 3.1

I want to use the RedirectAttibutes property introduced in Spring 3.1, I have the following handler method for the message in my controller

    @RequestMapping(value = "/register", method = RequestMethod.POST)
public String register(@ModelAttribute("admin") Admin admin, BindingResult bindingResult, SessionStatus sessionStatus, RedirectAttributes redirectAttributes) {
    redirectAttributes.addAttribute("admin", admin);
    if (bindingResult.hasErrors()) {
        return REGISTRATION_VIEW;

    }
    sessionStatus.setComplete();
    return "redirect:list";
}

But when I submit the form, I get the following exception:

java.lang.IllegalStateException: Argument [RedirectAttributes] is of type Model or Map but is not assignable from the actual model. You may need to switch newer MVC infrastructure classes to use this argument.
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.resolveHandlerArguments(HandlerMethodInvoker.java:322)

I came across several gotcha with redirectAttributes that cannot use ModelAndView as return type. Therefore, I returned only the representation of the string.

Can anyone pl. tell me where am i wrong

Thank.

+5
source share
1 answer

Spring 3.1 there is a new Spring version of the implementation of the MVC backend ( RequestMappingHandlerMapping/ RequestMappingHandlerAdapter) to replace the old ( DefaultAnnotationHandlerMapping/ AnnotationMethodHandlerAdapter).

Spring MVC 3.1, RedirectAttributes, .

<mvc:annotation-driven> @EnableWebMvc Spring MVC, . , HandlerMapping / HandlerAdapter , (, <mvc:annotation-driven>, ).

+15

All Articles