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>  

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM