No parameter name specified for argument of type
在使用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部分):
- @RequestMapping(value = "/security/login", method = RequestMethod.POST)
- public ModelAndView login(@RequestParam("userName") String userName,
- @RequestParam("password") String password,
- HttpServletRequest request) {
- ......................
参考:http://stackoverflow.com/questions/2622018/compile-classfile-issue-in-spring-3
No parameter name specified for argument of type的更多相关文章
- 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. ...
- 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 ...
- 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> # ...
- WebLogic下Argument(s) "type" can't be null.
启动项目出现Argument(s) "type" can't be null.异常.异常如下: java.lang.IllegalArgumentException: Argume ...
- React报错之Parameter 'props' implicitly has an 'any' type
正文从这开始~ 总览 当我们没有为函数组件或者类组件的props声明类型,或忘记为React安装类型声明文件时,会产生"Parameter 'props' implicitly has an ...
- React报错之Parameter 'event' implicitly has an 'any' type
正文从这开始~ 总览 当我们不在事件处理函数中为事件声明类型时,会产生"Parameter 'event' implicitly has an 'any' type"错误.为了解决 ...
- webservice cxf error:java.lang.IllegalArgumentException: Argument(s) "type" can't be null.
客户端请求DTO和服务器端的DTO定义不一样,客户端必须定义@XmlAccessorType和@XmlType,如: @XmlAccessorType(XmlAccessType.FIELD) @Xm ...
- Python学习笔记---形式参数(parameter)和实际参数(argument)
def mydemo(name): '函数定义过程中的name是叫形参' #因为它只是一个形式,表示占据一个参数位置 print('传递进来的' + name + '叫做实参,因为它是具体的参数值!' ...
- 编译问题:'<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上面没 ...
随机推荐
- 60、saleforce的future方法
测试future方法的异步执行 public with sharing class FutureSample { //future在自己线程中运行,直到资源可用才运行 @future public s ...
- JSHOP2
JSHOP2是一个HTN(hierarchy task network)规划器,是SHOP2(simple hierarchy ordered planner )的java实现版本. SHOP2的官网 ...
- Rust <7>:数据结构==>链表
enum List { Cons(u64, Box<List>), NULL, } impl List { fn new() -> List { List::NULL } fn pr ...
- cesium左侧列表定位目标
cesium左侧列表定位目标 功能:根据左侧列表经纬度等信息的值,进行搜索定位. 列表: 1 点击清除按钮可以清空所有input的值 2 点击查找可以定位到位置,如果输入的值不在范围内,会有弹出框 ...
- Python集成开发环境Pycharm+Git+Gitee(码云)
********************************************************************* 本文主要介绍集成开发环境的配置过程,方便多人协作办公.代码版 ...
- java.lang
package cn.sxt; import java.lang.*; public class BooleanDemo { public static void main(Stri ...
- 推荐Windows下SVN服务器端和客户端工具软件
相信很多人使用过Windows下的SVN客户端软件TortoiseSVN或者也有过Linux下.MAC下的SVN命令行使用经验,另外MAC下还有以一款就做Vesions的SVN客户端软件,不过个人感觉 ...
- (1.2)学习笔记之mysql体系结构(数据库文件)
InnoDB存储引擎体系结构图 1.InnoDB数据库的结构 (1)redo log:这里的redo log不是数据的redo log,InnoDB本也是一个数据库,身具有的redo log,所以这里 ...
- Rabbitmq的延时队列的使用
配置: spring: rabbitmq: addresses: connection-timeout: username: guest password: guest publisher-confi ...
- MySQL中orderby和limit分页数据重复的问题
背景 读取规则是按照某表中sequence字段排序的,而这个字段是让人手工填写的.那么,可想而知,数据一多,难免会出现填写的值相同的情况. 综上所述,可能就会导致以下两条sql出现数据重叠的情况: s ...