`

@PathVariable映射出现错误: Name for argument type

 
阅读更多
关于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方式进行下载,
@ResponseBody
    @RequestMapping(value = "/down/{_listid}/{type}", method = RequestMethod.GET)
    public ResponseEntity<byte[]> download(@PathVariable String _listid, @PathVariable String type) throws IOException {
    	......
    }

在idea和eclipse下面启动工程没问题, 但是部署的时候就出了问题,后台一直提示500错误,但看不到错误细节,后来我直接复制地址,打开标签,直接粘贴url,才看到下面错误:
org.springframework.web.util.NestedServletException: Request processing failed; 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.
org.springframework.web.servlet.FrameworkServlet.finalizeProcessing(FrameworkServlet.java:947)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:893)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:781)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:83)
com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)
root cause

java.lang.IllegalArgumentException: Name for argument type [java.lang.String] not available, and parameter name information not found in class file either.
org.springframework.util.Assert.notNull(Assert.java:112)
org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.updateNamedValueInfo(AbstractNamedValueMethodArgumentResolver.java:134)
org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.getNamedValueInfo(AbstractNamedValueMethodArgumentResolver.java:112)
org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:81)
org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:75)
org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:156)
org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:117)
org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:97)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandleMethod(RequestMappingHandlerAdapter.java:647)
org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:603)
org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:950)
org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:859)
org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:883)
org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:781)
javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:83)
com.opensymphony.sitemesh.webapp.SiteMeshFilter.obtainContent(SiteMeshFilter.java:129)
com.opensymphony.sitemesh.webapp.SiteMeshFilter.doFilter(SiteMeshFilter.java:77)


org.springframework.web.util.NestedServletException: Request processing failed; 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级别,比如
@RequestMapping(value = "/security/login", method = RequestMethod.POST)
public ModelAndView login(@RequestParam String userName, @RequestParam String password, 
    HttpServletRequest request) {

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



解决方法1:写全@RequestParam的参数
	@RequestMapping("hello")
	public String helloWorld(Map<String, Object> map, HttpServletRequest request,@RequestParam(value="hhh", required = false) String hhh) {

		System.out.println("hello");
		System.out.println("["+hhh+"]");
		map.put("message", "test message111");
		return "helloView";
	}

写全@PathVariable的参数
@RequestMapping(value="/users/{userId}/topics/{topicId}")
public String test(
       @PathVariable(value="userId") int userId, 
       @PathVariable(value="topicId") int topicId)      


解决方法2:修改build.xml,使用javac  debug=true
		<javac srcdir="${src}" destdir="${build}/WEB-INF/classes" debug="true" encoding="utf-8" classpathref="classpath" includeantruntime="on">
		</javac>
分享到:
评论
1 楼 xue88ming 2017-02-02  
很有用,谢谢

相关推荐

Global site tag (gtag.js) - Google Analytics