在Spring 3.1中重定向给IllegalStateException的属性
我想使用Spring3.1中出现的属性,我的控制器中有以下post处理程序方法在Spring 3.1中重定向给IllegalStateException的属性,spring,spring-mvc,Spring,Spring Mvc,我想使用Spring3.1中出现的属性,我的控制器中有以下post处理程序方法 @RequestMapping(value = "/register", method = RequestMethod.POST) public String register(@ModelAttribute("admin") Admin admin, BindingResult bindingResult, SessionStatus sessionStatus, RedirectAttributes re
@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";
}
但当我提交表格时,我得到了以下例外情况:
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)
我遇到了一些带有重定向属性的gotcha,您不能使用ModelAndView作为返回类型。所以我只返回了字符串视图
谁能告诉我哪里出了问题
谢谢。Spring 3.1引入了新版本的Spring MVC后端实现(
RequestMappingHandlerMapping
/RequestMappingHandlerAdapter
),以取代旧版本(DefaultAnnotationHandlerMapping
/AnnotationMethodHandlerAdapter
)
Spring MVC 3.1的一些新特性,如重定向属性
,仅受新实现的支持
如果您使用
或@EnableWebMvc
来启用springmvc,那么默认情况下应该启用新的实现。但是,如果手动声明HandlerMapping
和/或HandlerAdapter
,或使用默认实现,则需要显式切换到新实现(例如,如果切换到
,则不会中断您的配置)。@EnableWebMvc for the controller解决了此问题。应该在哪里添加“mvc:注释驱动”?