况描述:
web工程在windows环境eclipse下编译部署没有问题,系统升级时需要运维从Git取相应的源码并编译部署到线上机器,部署启动正常没有错误,当访问业务的action时报错,如下。
错误如下
- java.lang.IllegalArgumentException: Name for argument type [java.lang.String]
- not available, and parameter name information not found in class file either.
- at org.springframework.util.Assert.notNull(Assert.java:112)
- at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.updateNamedValueInfo(AbstractNamedValueMethodArgumentResolver.java:134)
- at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.getNamedValueInfo(AbstractNamedValueMethodArgumentResolver.java:112)
- at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:81)
- at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:75)
- at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:156)
- at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:117)
- at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:96)
- at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:617)
- at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:578)
- at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:80)
- at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:923)
- at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:852)
- at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:882)
- at org.springframework.web.servlet.FrameworkServlet.doGet(FrameworkServlet.java:778)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:114)
- at javax.servlet.http.HttpServlet.service(HttpServlet.java:91)
- at com.caucho.server.dispatch.ServletFilterChain.doFilter(ServletFilterChain.java:103)
- at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:88)
- at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
- at com.caucho.server.dispatch.FilterFilterChain.doFilter(FilterFilterChain.java:76)
- at com.caucho.server.cache.CacheFilterChain.doFilter(CacheFilterChain.java:158)
- at com.caucho.server.webapp.WebAppFilterChain.doFilter(WebAppFilterChain.java:178)
- at com.caucho.server.dispatch.ServletInvocation.service(ServletInvocation.java:241)
- at com.caucho.server.http.HttpRequest.handleRequest(HttpRequest.java:268)
- at com.caucho.server.port.TcpConnection.run(TcpConnection.java:586)
- at com.caucho.util.ThreadPool$Item.runTasks(ThreadPool.java:690)
- at com.caucho.util.ThreadPool$Item.run(ThreadPool.java:612)
- at java.lang.Thread.run(Thread.java:662)
这个错误主要是因为action的参数标注默认是debug级别,比如
@RequestMapping(value = "/security/login", method = RequestMethod.POST)
public ModelAndView login(@RequestParam String userName, @RequestParam String password,
HttpServletRequest request) {
此时userName的级别时debug级别,而在linux下编译时是忽略了这些标注,导致请求时就会找不到userName的参数。
解决方法:
1. 修改参数的写法,比如修改为
@RequestMapping(value = "/security/login", method = RequestMethod.POST)
public ModelAndView login(@RequestParam("userName") String userName,
@RequestParam("password") String password,
HttpServletRequest request) {
......................
2.修改编译脚本
- SRC=$(find ./java/* | grep java$)
- javac -g -d ./classes $SRC -encoding utf-8
增加 -g 参数,即编译时生成所有debug的信息。
为了这个问题费了很大劲,主要参考了了
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的写法有些问题,改为上面的写法便可。