0
我正在嘗試爲Spring MVC應用程序添加國際化和本地化支持。Spring MVC中的區域設置
在我的dispatcherServlet.xml,我在web.xml中使用DefaultAnnotationHandlerMapping
映射
<bean class="org.springframework.web.servlet.mvc.annotation.DefaultAnnotationHandlerMapping" >
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor" />
</list>
</property>
</bean>
<web-app>
<display-name>Archetype Created Web Application</display-name>
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>
org.springframework.web.servlet.DispatcherServlet
</servlet-class>
<init-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring/dispatcherservlet.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>*.html</url-pattern>
</servlet-mapping>
<welcome-file-list>
<welcome-file>redirect.jsp</welcome-file>
</welcome-file-list>
我控制器
@Controller
@RequestMapping(value = "/account")
public class AccountController {
@RequestMapping(method = RequestMethod.GET)
public String index() {
return "index";
}
@RequestMapping(value = "/register", method = RequestMethod.GET)
public String showForm(Map<String, Object> mm) {
mm.put("subcriber", new Sucriber());
return "register";
}
@RequestMapping(value = "/register", method = RequestMethod.POST)
public String register(@ModelAttribute("subcriber") Sucriber sucriber,BindingResult result,Map<String, Object> mm) {
SucriberValidator sucriberValidator = new SucriberValidator();
sucriberValidator.validate(sucriber, result);
if (result.hasErrors()) {
return "register";
} else {
return "success";
}
}
}
當我去myhost/myhost:myport/myproject,每件事都OK 但類DefaultAnnotationHandlerMapping
已棄用。 在Spring 3.2中支持RequestMappingHandlerMapping
。所以我使用類RequestMappingHandlerMapping
。
<bean class="org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping" >
<property name="interceptors">
<list>
<ref bean="localeChangeInterceptor" />
</list>
</property>
</bean>
當我去MYHOST /爲myhost:MyPort上/ myproject,而我得到的錯誤
HTTP狀態500 - 無適配器處理程序[公共java.lang.String中controller.AccountController.index( )]:DispatcherServlet的配置需要包括支持該處理器
感謝任何幫助
檢查此http://stackoverflow.com/questions/18287711/spring-mvc-3-localechangeinterceptor。 – apurvc
當我使用RequestMappingHandlerMapping替換DefaultAnnotationHandlerMapping時,會發生問題。我不知道爲什麼。我將@RequestMapping(value =「/」,method = RequestMethod.GET)添加到索引方法,但結果仍爲HTTP狀態404 –
如果使用'RequestMappingHandlerMapping',則還需要添加'RequestMappingHandlerAdapter'。但是,使用' '然後使用' '來註冊攔截器會更容易。 –