Spring MVC报异常:org.springframework.web.util.NestedServletException: Request processing failed

在使用SpringMVC绑定基本类型(如String,Integer等)参数时,应通过@RequestParam注解指定具体的参数名称,否则,当源代码在非debug模式下编译后,运行时会引发HandlerMethodInvocationException异常,这是因为只有在debug模式下编译,其参数名称才存储在编译好的代码中。

譬如下面的代码会引发异常:

@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) {

......................

时间: 2024-12-28 08:33:34

Spring MVC报异常:org.springframework.web.util.NestedServletException: Request processing failed的相关文章

error:org.springframework.web.util.NestedServletException: Request processing failed; nested exception is java.lang.NullPointerException

问题:调用的方法在一个接口类中,但我并没有注入那个被调用的类 解决:在UserEntity前加上@Autowired @Controller public class MainController { // 自动装配数据库接口,不需要再写原始的Connection来操作数据库 @Autowired UserRepository userRepository; @RequestMapping(value = "/",method = RequestMethod.GET) public S

org.springframework.web.util.NestedServletException: Request processing failed; nested exception is org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.jboss.resteasy.plug

之前做的项目是resteasy的上传,代码没有问题,断点都不进来呢. 我以为可以直接移植到SpringMVC,但是SpringMVC不支持MultipartFormDataInput , 用MultipartFile就可以了.老的无法兼容新的.正确代码如下 @RequestMapping(value = "/importExcelForEduQuestion",produces = "application/json; charset=utf-8")@Respons

org.springframework.web.util.NestedServletException Handler processing failed; n

因为谷歌的lists不支持或使用, 所有要改成java的list工具 谷歌list使用: import com.google.common.collect.Lists; .... Lists.newArrayList()java list 使用: List<String> list =new ArrayList<>(); 原文地址:https://www.cnblogs.com/yysbolg/p/8565586.html

HTTP Status 500 - Request processing failed; nested exception is org.springframework.jdbc.BadSqlGram

HTTP Status 500 - Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: type Exception report message Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: descriptio

maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener

本篇文章主要介绍了"maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener ",主要涉及到maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener 方面的内容,对于maven web 项目中启动报错jav

maven web启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener

问题描述 SEVERE: Error configuring application listener of class org.springframework.web.util.Log4jConfigListener java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener 解决方案同 maven项目Tomcat controller 404

Spring MVC全局异常后返回JSON异常数据

Spring MVC全局异常后返回JSON异常数据 问题: 当前项目是作为手机APP后台支持,使用spring mvc + mybaits + shiro进行开发.后台服务与手机端交互是发送JSON数据.如果后台发生异常,会直接返回异常页面,显示异常内容,如果是404请求不到资源或者500这类服务器的问题,可能会导致返回404和500异常页面,手机端的处理就非常麻烦,为了解决这个问题,就需要做全局的异常处理. 解决方案: (1)自定义或者使用spring自带的各种异常处理器 例如spring基于

Error configuring application listener of class org.springframework.web.util.IntrospectorCleanupListener

I had a similar problem when running a spring web application in an Eclipse managed tomcat. I solved this problem by adding maven dependencies in the project's web deployment assembly. 找到解决方案: Open the project's properties (e.g., right-click on the p

tomcat报错org.springframework.web.context.ContextLoaderListener找不到

tomcat报错org.springframework.web.context.ContextLoaderListener找不到. 最后解决办法:将jar包copy到web-inf下面的lib中. 你可以在web app libary是不是空,或者点不开. 引用网友的: http://topic.csdn.net/u/20090216/19/3c955432-e708-4338-961f-8db9db7f5df1.html 可能是jar包位置导致的. Java虚拟机是根据Java ClassLo