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

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

  1. @RequestMapping(value = "/security/login", method = RequestMethod.POST)
  2. public ModelAndView login(@RequestParam String userName, @RequestParam String password,
  3. HttpServletRequest request) {
  4. ......................

如果使用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部分):

  1. @RequestMapping(value = "/security/login", method = RequestMethod.POST)
  2. public ModelAndView login(@RequestParam("userName") String userName,
  3. @RequestParam("password") String password,
  4. HttpServletRequest request) {
  5. ......................

参考:http://stackoverflow.com/questions/2622018/compile-classfile-issue-in-spring-3

No parameter name specified for argument of type的更多相关文章

  1. Go Concurrency Patterns: Context At Google, we require that Go programmers pass a Context parameter as the first argument to every function on the call path between incoming and outgoing requests.

    小结: 1. Background is the root of any Context tree; it is never canceled: 2.     https://blog.golang. ...

  2. Format specifies type 'int' but the argument has type 'struct node *'

    /Users/Rubert/IOS/iworkspace/LineList/LineList/main.c::: Format specifies type 'int' but the argumen ...

  3. Ubuntu gcc编译报错:format ‘%llu’ expects argument of type ‘long long unsigned int’, but argument 2 has type ‘__time_t’ [-Wformat=]

    平时用的都是Centos系统,今天偶然在Ubuntu下编译了一次代码,发现报错了: 源码: #include <stdio.h> #include <sys/time.h> # ...

  4. WebLogic下Argument(s) "type" can't be null.

    启动项目出现Argument(s) "type" can't be null.异常.异常如下: java.lang.IllegalArgumentException: Argume ...

  5. React报错之Parameter 'props' implicitly has an 'any' type

    正文从这开始~ 总览 当我们没有为函数组件或者类组件的props声明类型,或忘记为React安装类型声明文件时,会产生"Parameter 'props' implicitly has an ...

  6. React报错之Parameter 'event' implicitly has an 'any' type

    正文从这开始~ 总览 当我们不在事件处理函数中为事件声明类型时,会产生"Parameter 'event' implicitly has an 'any' type"错误.为了解决 ...

  7. webservice cxf error:java.lang.IllegalArgumentException: Argument(s) "type" can't be null.

    客户端请求DTO和服务器端的DTO定义不一样,客户端必须定义@XmlAccessorType和@XmlType,如: @XmlAccessorType(XmlAccessType.FIELD) @Xm ...

  8. Python学习笔记---形式参数(parameter)和实际参数(argument)

    def mydemo(name): '函数定义过程中的name是叫形参' #因为它只是一个形式,表示占据一个参数位置 print('传递进来的' + name + '叫做实参,因为它是具体的参数值!' ...

  9. 编译问题:'<invalid-global-code>' does not contain a definition for 'Store' and no extension method 'XXX' accepting a first argument of type '<invalid-global-code>' could be found

    这是VS2015上的bug. 我碰到的时候,是VS在合并两个分支的代码时,多加了一个}.导致编译语法报错.. 解决办法就是在错误的附近,找找有没有多余的大括号,删掉即可. 这个问题在vs2017上面没 ...

随机推荐

  1. 46、tensorflow入门初步,手写识别0,1,2,3,4,5,6

    1.使用tensorflow的SoftMax函数,对手写数字进行识别 Administrator@SuperComputer MINGW64 ~ $ docker run -it -p 8888:88 ...

  2. Linux中grep命令,用或的关系查询多个字符串,正则表达式基础说明

    请尊重版权:原文:https://blog.csdn.net/lkforce/article/details/52862193 使用 grep 'word1|word2' 文件名  这样的命令是不对的 ...

  3. UML指南系列——用例图

    可以用用例来描述正在开发的系统想要实现的行为,而不必说明这些行为如何实现. 结构良好的用例只表示系统或者子系统的基本行为,而且既不过于笼统也不过于详细.

  4. shell 跟踪命令

    添加跟踪 set -x 去除跟踪 set +x

  5. [已解决]报错: TLS handshake timeout

    为了永久性保留更改,您可以修改 /etc/docker/daemon.json 文件并添加上 registry-mirrors 键值. { "registry-mirrors": ...

  6. Codeforces 488C Fight the Monster

    Fight the Monster time limit per test             1 second                                   memory ...

  7. OpenGL中的空间变换

    OpenGL中的空间变换          在使用OpenGL的三维虚拟程序中.当我们指定了模型的顶点之后.在屏幕上显示它们之前,一共会发生3种类型的变换:视图变换.模型变换.投影变换.        ...

  8. Arcpy 将要素类添加到当前工作窗口(内容列表)

    test1layer=arcpy.mapping.Layer( folder+"\\"+"result.shp") mxd = arcpy.mapping.Ma ...

  9. android 批量加载数据

    public class MainActivity extends Activity { private ListView listView; private List<String> d ...

  10. java web session共享

    一 搭建环境 操作系统:windows 7 64位 http server:nginx 1.9.7 缓存系统:memcached Servlet容器:apache-tomcat-7.0.65 二 搭建 ...