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上面没 ...
随机推荐
- linux下安装JMeter(小白教程)
用windows平台测试时,会受到网络条件的影响,导致测试结果不够准确,尤其是高并发的情况下,需要能够精准的测试请求的响应时长,对于网络的要求更加苛刻.在这样的情况下,可以考虑在linux服务器端安装 ...
- java 重新学习 (四)
一.内部类成员可以直接访问外部类的私有数据,因为内部类被当成其外部类成员,同一个类中的成员之间可以相互访问.但外部类不能访问内部类的实现细节,例如内部类的成员变量.匿名内部类适合用于创建仅需要一次使用 ...
- 都 9102 年了,一起来攻克 Linux 吧!
都 9102 年了,一起来攻克 Linux 吧! 对 Java 程序员来说,天天会和 Linux 打交道,如果你无法熟练地操作 Linux ,基本上等于少了一半的功力,也少了一半的机会-- 身边的开发 ...
- FrameWork内核解析之XMS内核管理(一)上篇
阿里P7Android高级架构进阶视频免费学习请点击:https://space.bilibili.com/474380680本篇文章将继续从以下两个内容来介绍XMS内核管理之AMS: [Activi ...
- 微信公众号开发笔记-验证token
开发 话不多说我们直接进入主题 我们先去微信公众号申请一个公众号: 申请完成之后我们找到开发下的基本配置 然后找到进行基本配置,我们需要一个url地址来验证,这里的地址必需要是外网,Token是我们任 ...
- SpringMVC入门及拦截器
SSM最后一个框架springmvc,其实上手特别简单.但是我昨天看一个深入源码的视频,差点GG.其实以前学过很多东西,都忘了,不敢说学会,现在有了本书,看过一遍之后.多多少少记住一些,权当我会用了, ...
- SpringMVC(IntelliJ IDEA)(详细操作)
1. 2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15.
- ACM之map常用用法
map 在STL的头文件中<map>中定义了模版类map和multimap,用有序二叉树表存储类型为pair<const Key, T>的元素对序列.序列中的元素以const ...
- arcpy-字段唯一值、重复值、最值、平均值、方差、标准差、中数、众数
插个广告,制作ArcGIS的Tool工具学习下面的教程就对了: 零基础学习Python制作ArcGIS自定义工具观看链接 <零基础学习Python制作ArcGIS自定义工具>课程简介 im ...
- 为什么要用webpack!
为什么要用webpack? 现今的很多网页其实可以看做是功能丰富的应用,它们拥有着复杂的JavaScript代码和一大堆依赖包. 模块化,让我们可以把复杂的程序细化为小的文件; 类似于Type ...