zoukankan      html  css  js  c++  java
  • 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>  
  • 相关阅读:
    Javascript MVC学习杂记3
    Backbone.js 0.9.2 源码分析收藏
    Javascript MVC学习杂记2
    Javascript MVC学习杂记1
    C语言string.h中常用字符函数介绍
    10点网页设计要注意的细节
    js日期函数
    结合回调函数介绍下泛型函数
    【转载】互斥量和信号量的区别
    设计模式之Singleton
  • 原文地址:https://www.cnblogs.com/xue88ming/p/7182987.html
Copyright © 2011-2022 走看看