在使用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. 8、数值分析与matlab

    1.今天要拷matlab代码了,而且是很恶心的算法,估计也没几个人能看得懂,就连我自己都看不懂. 我也不知道这样做的意义何在,可能只是证明我在这世上曾经学过那么那么难的东西吧 首先是一个matlab版 ...

  2. 政府网站综合防护系统(网防G01)

    政府网站综合防护系统,简称“网防G01”,是首款专门针对政府网站及服务器等关键信息基础资源进行综合防护的产品,由公安部第一研究所和计算机病毒防治技术国家工程实验室(北京)研发. 网防G01的架构 由服 ...

  3. ztree 数组和树结构互转算法

    //树转化为数组transformToArrayFormat: function (setting, nodes) { if (!nodes) return []; var childKey = se ...

  4. volatile在嵌入式系统中的用法

    今天参加一家公司的嵌入式C语言笔试,其中有道主观题谈到在嵌入式系统中volatile变量的用法.平时学习C语言没怎么用到,只用到过static和extern的变量,很惭愧没答上来.嵌入式C语言笔试经常 ...

  5. Mysql 主从同步(转载)

    第一步: 在master上创建用于同步的用户 GRANT FILE,REPLICATION SLAVE,REPLICATION CLIENT,SUPER ON *.* TObackup@'192.16 ...

  6. [Fw]How to Add a System Call(Fedora Core 6 Kernel : 2.6.18)

    How to Add a System Call Kernel : 2.6.18編譯環境 : Fedora Core 6 假設要加的system call為 sys_project, 有一個int的輸 ...

  7. c数据结构的字符串查找的Brute-Force算法

    #include<stdio.h> #include<malloc.h> #include<string.h> //定义字符串的结构体 typedef struct ...

  8. Redis事务 和 pipleline

    1.reidis事务 Redis 事务可以一次执行多个命令, 并且带有以下三个重要的保证: 批量操作在发送 EXEC 命令前被放入队列缓存. 收到 EXEC 命令后进入事务执行,事务中任意命令执行失败 ...

  9. 从Airbnb的发展历程和网易云的大起大落看IT行业创新(第5周课后作业)

    我想先根据个人看法回答“创新是什么?”这个空泛的问题.创新是面对当下的资源条件限制创造出能够满足动态需求或解决动态发展中的问题的新策略.这种实用化定义在大部分邻域都勉强能让定义者自圆其说,对于IT行业 ...

  10. jq 将translate的旋转角度转为数值

    // 将translate内的角度转为数值 function getmatrix(nowDeg){ var values = nowDeg.split('(')[1].split(')')[0].sp ...