在使用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. 用 Flask 来写个轻博客 (14) — M(V)C_实现项目首页的模板

    Blog 项目源码:https://github.com/JmilkFan/JmilkFan-s-Blog 目录 目录 前文列表 实现所需要的视图函数 实现 home.html 模板 代码分析 实现效 ...

  2. jmeter 响应超时时间设置 压力增大,不能正常退出全部线程

    当压力增大会出现connect timeout error 压力增大,不能正常退出全部线程: 解决办法:http request default--advance--timeouts 如填写1,表示大 ...

  3. shell编程2:数组的运用

    Shell 数组 定义数组 在Shell中,用括号来表示数组,数组元素用"空格"符号分割开.定义数组的一般形式为: name=(name1 name2 name3) 复制代码 还可 ...

  4. leetcode.矩阵.378有序矩阵中第K小的元素-Java

    1. 具体题目 给定一个 n x n 矩阵,其中每行和每列元素均按升序排序,找到矩阵中第k小的元素.请注意,它是排序后的第k小元素,而不是第k个元素. 示例: matrix = [ [ 1,  5, ...

  5. python操作xls表

    1.python读取excel中单元格内容为日期的方式 python读取excel中单元格的内容返回的有5种类型,即上面例子中的ctype: ? 1 ctype : 0 empty,1 string, ...

  6. TOPO DN 解析

    介绍     有一个算法,是将大量TOPO DN实例解析成结构形式.并依据DN获取对应的数据.本人感觉值得分享.并供大家讨论与优化.     注意:TOPO DN实例的顺序,是被我的其他算法预处理过的 ...

  7. 10个艰难的Java面试题与答案

    10个最难回答的Java面试题 这是我收集的10个较难回答的 Java 面试题.这些问题主要来自 Java 核心部分 ,不涉及 Java EE 相关问题.这些问题都是容易在各种 Java 面试中被问到 ...

  8. Arcpy 遍历每一个要素新建要素类

    #方法一:cursor= arcpy.da.SearchCursor(aim_fc,["OID@","SHAPE@"]) for row in cursor: ...

  9. esxi主机用命令行强行关闭通过前端界面无法关闭的ESXI虚拟机

    环境:esxi5.1-esxi6.5 背景:如果esxi下面某一台vm死机了,并且esxi的控制台卡死不能用,为了不影响同一个esx下其他的vm正常使用,那么我们只能用命令行来单独重启此vm,保证一定 ...

  10. js异步处理

    一.什么是异步? 我们一般喜欢把异步和同步.并行拿出来比较,我以前的理解总是很模糊,总是生硬地记着“同步就是排队执行,异步就是一起执行”,现在一看,当初简直就是傻,所以我们第一步先把这三个概念搞清楚, ...