`

Name for argument type [java.lang.String] not available

阅读更多

转载自 http://panyongzheng.iteye.com/blog/2222666 谢谢 保留收藏

关于spring java.lang.IllegalArgumentException: Name for argument type [java.lang.String] 的错误 http://blog.csdn.net/liuguanghaoputin/article/details/8695600 
Name for argument type [java.lang.String] not available http://m.blog.csdn.net/blog/kouwoo/42869779 
SpringMVC强大的数据绑定(2)——第六章 注解式控制器详解——跟着开涛学SpringMVC http://jinnianshilongnian.iteye.com/blog/1705701 



为了这个问题费了很大劲,主要参考了了 
1.http://stackoverflow.com/questions/2622018/compile-classfile-issue-in-spring-3   这个主要是因为ant编译导致类似的问题。 

2.  http://stackoverflow.com/questions/10305592/error-class-names-are-only-accepted-if-annotation-processing-is-explicitly-req    一开始src的写法有些问题,改为上面的写法便可。 



发现问题: 
一次做下载过程中,使用get方式进行下载, 

Java代码  收藏代码
  1. @ResponseBody  
  2.     @RequestMapping(value = "/down/{_listid}/{type}", method = RequestMethod.GET)  
  3.     public ResponseEntity<byte[]> download(@PathVariable String _listid, @PathVariable String type) throws IOException {  
  4.         ......  
  5.     }  


在idea和eclipse下面启动工程没问题, 但是部署的时候就出了问题,后台一直提示500错误,但看不到错误细节,后来我直接复制地址,打开标签,直接粘贴url,才看到下面错误: 

Error 500: org.springframework.web.util.NestedServletException: 

Request processing failed&#59; nested exception is java.lang.IllegalArgumentException: 

Name for argument type [java.lang.String] not available, and parameter name information not found in class file either.

 


原因: 
这个错误主要是因为action的参数标注默认是debug级别,比如 

Java代码  收藏代码
  1. @RequestMapping(value = "/security/login", method = RequestMethod.POST)  
  2. public ModelAndView login(@RequestParam String userName, @RequestParam String password,   
  3.     HttpServletRequest request) {  


此时userName的级别时debug级别,而在linux下编译时是忽略了这些标注,导致请求时就会找不到userName的参数。eclipse默认是debug级别的函数里面的参数名保留,但是ant编译就不行了。 



解决方法1:写全@RequestParam的参数 

Java代码  收藏代码
  1. @RequestMapping("hello")  
  2. public String helloWorld(Map<String, Object> map, HttpServletRequest request,@RequestParam(value="hhh", required = false) String hhh) {  
  3.   
  4.     System.out.println("hello");  
  5.     System.out.println("["+hhh+"]");  
  6.     map.put("message""test message111");  
  7.     return "helloView";  
  8. }  


写全@PathVariable的参数 

Java代码  收藏代码
  1. @RequestMapping(value="/users/{userId}/topics/{topicId}")  
  2. public String test(  
  3.        @PathVariable(value="userId"int userId,   
  4.        @PathVariable(value="topicId"int topicId)        



解决方法2:修改build.xml,使用javac  debug=true 

Xml代码  收藏代码
  1. <javac srcdir="${src}" destdir="${build}/WEB-INF/classes" debug="true" encoding="utf-8" classpathref="classpath" includeantruntime="on">  
  2. </javac>  
分享到:
评论

相关推荐

    java.lang.IllegalArgumentException Cannot format given Object as a Date

    在Java编程中,`java.lang.IllegalArgumentException` 是一个标准的运行时异常,它通常表示一个方法接收到的参数值不在预期范围内或者不合法。当尝试将一个无法转换为日期的对象格式化时,就会抛出"Cannot format ...

    用javah导出类的头文件常见的错误及正确的使用方法.docx

    Exception in thread "main" java.lang.IllegalArgumentException: Not a valid class name: HelloJNIActivity.class ``` 这是因为`javah`命令期望的是类的全名,而不是包含扩展名的文件名。解决方法是只提供类的...

    Addison.Wesley.The.Java.Programming.Language.4th.Edition.Aug.2005.chm

    It also covers most of the classes in the main packages (java.lang, java.util, java.io) as implemented in the J2SE™ Development Kit 5.0 (more commonly known as JDK 5.0, or in the older nomenclature ...

    default argument missing for function name (解决方案).md

    default argument missing for function name (解决方案).md

    解决yolov3_object_tracking中loop of ufunc does not support argument 0 of type Tensor which has问题

    TypeError: loop of ufunc does not support argument 0 of type Tensor which has no callable arctan method 报错行 self.u = np.round(np.dot(self.F, self.u)) #或者 self.u = np.round(self.u + np.dot(K, ...

    javaweb编程中常见的异常及处理方法.doc

    本文将重点介绍一种常见的异常——`java.lang.IllegalArgumentException: argument type mismatch`,并详细解析其成因与解决策略。 #### 异常示例 在JavaWeb项目中使用Struts框架时,可能会遇到如下异常: ```java...

    'FrontEnd Plus' The GUI for the fast JAva Decompiler.

    Jad uses JAVA class name as an output file name. For example, if class file 'example1.class' contains JAVA class 'test1' then Jad will create file 'test1.jad' rather than 'example1.jad'. If you want ...

    Python库 | polidoro-py-argument-2.1.0.tar.gz

    "Python库 | polidoro-py-argument-2.1.0.tar.gz"是一个与Python相关的库,其版本为2.1.0,被打包成tar.gz格式的压缩文件。这个库的名字叫做“polidoro-py-argument”,从名称可以推测它可能专注于处理命令行参数或...

    spleeter-master.zip

    《Spleeter:最佳音轨分离软件的深度解析与应用》 Spleeter,这款被誉为“最好用的音轨分离软件”,是音频处理领域的一颗璀璨明珠。它以其卓越的性能,将音频分类和人声提取提升到了新的高度。...

    servlet2.4doc

    Overrides the standard java.lang.Object.clone method to return a copy of this cookie. containsHeader(String) - Method in class javax.servlet.http.HttpServletResponseWrapper The default behavior of ...

    解决Jave在linux下转为MP3时为0字节或其他异常或转码后只有1分钟时长

    通过解读源码,在windows下ok,而在linux下解析格式有所不同才导致上面的各种异常,最终修改了源码包中的Encoder.java,整合ffmpeg-2.7.2-x64版本 3、转码后MP3时长最多一分钟 参考文献: 1、jave-1.0.2源码下载...

    mtk Factory mode.zip

    在分析和修改源码时,开发者需要具备一定的安卓应用开发知识,包括Java或Kotlin编程语言、Android SDK的使用,以及对Android系统框架的理解。同时,理解MTK的开发工具和API也是必要的,这通常涉及到NDK(Native ...

    java内功修炼.pdf

    Java 内功修炼主要涉及了三个关键知识点:静态导入、可变参数以及增强for循环。这些特性都是自Java 5版本引入的,极大地提升了代码的可读性和便捷性。 1. **静态导入(Static Import)** 静态导入是Java 1.5引入的...

    SystemVerilog for Design(2nd edition)

    3.2.1 Macro argument substitution within strings.....................................................39 3.2.2 Constructing identifier names from macros....................................................

    JSP Simple Examples

    Constructor declaration are just like method declaration, except that they do not have any return type and they use the name of the class. The compiler provides us with a default constructor to the ...

    jna-4.2.2 官方原版下载

    Automatic mapping from Java to native functions, with simple mappings for all primitive data types Runs on most platforms which support Java Automatic conversion between C and Java strings, with ...

    python3.6.5参考手册 chm

    PEP 3155: Qualified name for classes and functions PEP 412: Key-Sharing Dictionary PEP 362: Function Signature Object PEP 421: Adding sys.implementation SimpleNamespace Using importlib as the ...

Global site tag (gtag.js) - Google Analytics