在使用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. 2017《Java技术》预备作业 计科1502任秀兴

    阅读邹欣老师的博客,谈谈你期望的师生关系是什么样的? 我认为,学生和老师的关系,应该亦师亦友.可以以一种朋友的身份去进行教学,是我们理想中的课堂. 在生活中,老师和我们应该多沟通,成为朋友,在有感情的 ...

  2. 用php写爬虫去爬数据

    参考文档1 参考文档2 这里是我自己写的一个小需求 <?php /** 采集http://www.959.cn/school,即时更新的最新的文章内容:每分钟采集一次.采集结束后实时入库并展示. ...

  3. PAT_A1131#Subway Map

    Source: PAT A1131 Subway Map (30 分) Description: In the big cities, the subway systems always look s ...

  4. 使用正则限制input框只能输入数字/英文/中文等等

    常用HTML正则表达式 1.只能输入数字和英文的: 复制代码代码如下: <input onkeyup="value=value.replace(/[/W]/g,'') " o ...

  5. python 根据字典的键值进行排序

    1.利用key排序 d = {'d1':2, 'd2':4, 'd4':1,'d3':3,} for k in sorted(d): print(k,d[k]) d1 2d2 4d3 3d4 1 2. ...

  6. python+tushare获取沪深港股通持股明细

    接口:hk_hold 描述:获取沪深港股通持股明细,数据来源港交所. 限量:单次最多提取3800条记录,可循环调取,总量不限制 积分:用户积120积分可调取试用,2000积分可正常使用,单位分钟有流控 ...

  7. python 包管理工具 pip 的配置

    近几年来,python的包管理系统pip 越来越完善, 尤其是对于 windows场景下,pip大大改善了python的易用性. https://www.cnblogs.com/yvivid/p/pi ...

  8. [轉]Linux 2.6内核笔记【内存管理】

    4月14日 很多硬件的功能,物尽其用却未必好过软实现,Linux出于可移植性及其它原因,常常选择不去过分使用硬件特性. 比如 Linux只使用四个segment,分别是__USER_CS.__USER ...

  9. 自定义DbUtils通用类

    本实例使用C3P0连接池做连接,详见https://www.cnblogs.com/qf123/p/10097662.html开源连接池C3P0的使用 DBUtils.java package com ...

  10. Codeforces 1105E 最大独立集 状态DP 中途相遇法

    题意:你有一个字符串, 有两种操作,一种是改变字符串,一种是某个用户询问这个字符串,如果一个用户每次查询字符串的时候都是他的用户名,他就会高兴.问最多有多少个用户会高兴? 题意:容易发现,在两个1操作 ...