Spring MVC报异常:org.springframework.web.util.NestedServletException: Request processing failed
2014-03-06 09:12
555 查看
在使用SpringMVC绑定基本类型(如String,Integer等)参数时,应通过@RequestParam注解指定具体的参数名称,否则,当源代码在非debug模式下编译后,运行时会引发HandlerMethodInvocationException异常,这是因为只有在debug模式下编译,其参数名称才存储在编译好的代码中。
譬如下面的代码会引发异常:
Java代码
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.bind.annotation.support.HandlerMethodInvocationException:
Failed to invoke handler method [public org.springframework.web.servlet.ModelAndView com.mypackage.security.controller.LoginController.login(java.lang.String,java.lang.String,javax.servlet.http.HttpServletRequest)]; nested exception is java.lang.IllegalStateException: No parameter name specified for argument of type [java.lang.String], and no parameter name information found in class file either.
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:659)
..........
org.springframework.web.bind.annotation.support.HandlerMethodInvocationException: Failed to invoke handler method [public org.springframework.web.servlet.ModelAndView com.mypackage.security.controller.LoginController.login(java.lang.String,java.lang.String,javax.servlet.http.HttpServletRequest)]; nested exception is java.lang.IllegalStateException: No parameter name specified for argument of type [java.lang.String], and no parameter name information found in class file either.
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
..........
java.lang.IllegalStateException: No parameter name specified for argument of type [java.lang.String], and no parameter name information found in class file either.
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.getRequiredParameterName(HandlerMethodInvoker.java:618)
..........
Java代码
@RequestMapping(value = "/security/login", method = RequestMethod.POST)
public ModelAndView login(@RequestParam("userName") String userName, @RequestParam("password") String password, HttpServletRequest request) {
......................
譬如下面的代码会引发异常:
Java代码
@RequestMapping(value = "/security/login", method = RequestMethod.POST) public ModelAndView login(@RequestParam String userName, @RequestParam String password, HttpServletRequest request) { ...................... 如果使用Eclipse编译不会在运行时出现异常,这是因为Eclipse默认是采用debug模式编译的,但是如果使用Ant通过javac任务编译的话就会出现异常,除非指定debug=”true”。出现的异常如同:
org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.web.bind.annotation.support.HandlerMethodInvocationException:
Failed to invoke handler method [public org.springframework.web.servlet.ModelAndView com.mypackage.security.controller.LoginController.login(java.lang.String,java.lang.String,javax.servlet.http.HttpServletRequest)]; nested exception is java.lang.IllegalStateException: No parameter name specified for argument of type [java.lang.String], and no parameter name information found in class file either.
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:659)
..........
org.springframework.web.bind.annotation.support.HandlerMethodInvocationException: Failed to invoke handler method [public org.springframework.web.servlet.ModelAndView com.mypackage.security.controller.LoginController.login(java.lang.String,java.lang.String,javax.servlet.http.HttpServletRequest)]; nested exception is java.lang.IllegalStateException: No parameter name specified for argument of type [java.lang.String], and no parameter name information found in class file either.
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.invokeHandlerMethod(HandlerMethodInvoker.java:171)
..........
java.lang.IllegalStateException: No parameter name specified for argument of type [java.lang.String], and no parameter name information found in class file either.
org.springframework.web.bind.annotation.support.HandlerMethodInvoker.getRequiredParameterName(HandlerMethodInvoker.java:618)
..........
最好的做法是通过@RequestParam注解指定具体的参数名称,如,上面的代码应该如此编写(注意@RequestParam部分):
Java代码
@RequestMapping(value = "/security/login", method = RequestMethod.POST)
public ModelAndView login(@RequestParam("userName") String userName, @RequestParam("password") String password, HttpServletRequest request) {
......................
相关文章推荐
- Spring MVC报异常:org.springframework.web.util.NestedServletException: Request processing failed
- org.springframework.web.util.NestedServletException: Request processing failed; nested exception is
- spring + ibatis错误总结org.springframework.web.util.NestedServletException: Request processing failed; n
- org.springframework.web.util.NestedServletException: Request processing failed; nested exception is
- org.springframework.web.util.NestedServletException: Request processing failed; nested exception is
- org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: Unknown column 'viewpoint' in 'field list'
- org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.jboss.resteasy.plug
- error:org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException
- 【已解决】org.springframework.web.util.NestedServletException: Request processing failed; nested exceptio
- hibernate org.springframework.web.util.NestedServletException: Request processing failed; nested exc
- org.springframework.web.util.NestedServletException: Request processing failed; nested exception is
- org.springframework.web.util.NestedServletException: Request processing fail
- org.springframework.web.util.NestedServletException: Request processing fail
- org.springframework.web.util.NestedServletException: Handler processing failed; nested exception is
- Spring MVC集成thymeleaf时提示:defined in ServletContext resource [/WEB-INF/SrpingMVCTest-servlet.xml]: Instantiation of bean failed; nested exception is org.springframework.beans.BeanInstantiationException
- Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException
- mapper绑定异常 springframework.web.util.NestedServletException
- Request processing failed; nested exception is org.springframework.dao.InvalidDataAccessApiUsageExce
- 错误:严重: Servlet.service() for servlet [appServlet] in context with path [] threw exception [Request processing failed; nested exception is org.mybatis.spring.MyBatisSystemException: nested exception is