Think about springmvc Parameter Parsing from an exception, and springmvc Parameter Parsing
First, record the exceptions and the causes and solutions.
Exception information:
2016-10-12 12:40:46,808 ERROR [500.jsp] - Name for argument type [java.lang.String] not available, and parameter name information not found in class file either.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.web.method.annotation.AbstractNamedValueMethodArgumentResolver.updateNamedValueInfo(AbstractNamedValueMethodArgumentResolver.java:141) at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.getNamedValueInfo(AbstractNamedValueMethodArgumentResolver.java:119) at org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(AbstractNamedValueMethodArgumentResolver.java:86) at org.springframework.web.method.support.HandlerMethodArgumentResolverComposite.resolveArgument(HandlerMethodArgumentResolverComposite.java:78) at org.springframework.web.method.support.InvocableHandlerMethod.getMethodArgumentValues(InvocableHandlerMethod.java:162) at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:129) at org.springframework.web.method.annotation.ModelFactory.invokeModelAttributeMethods(ModelFactory.java:136)
Let me talk about my solution. Based on the exception prompt, I tracked the resolveArgument method of AbstractNamedValueMethodArgumentResolver, and then saw its role from the interface, that is
Process the parameters of the ing method in the processor
The inheritance diagram also shows that any annotation in the parameter calls the processor, including @ RequetParam, @ PathVaiable, @ Value, @ RequestHeader @ Value @ CookieValue @ MatrixVariable each annotation can be executed by Baidu.
Souga! I probably know the problem in these annotations in my project. Then I can see it in debug.
org.springframework.web.method.annotation.AbstractNamedValueMethodArgumentResolver.resolveArgument(MethodParameter, ModelAndViewContainer, NativeWebRequest, WebDataBinderFactory)
If the parameters in this method are correct, the first one is the method representing the processor. Let's continue to look at the following code:
private NamedValueInfo updateNamedValueInfo(MethodParameter parameter, NamedValueInfo info) {String name = info.name;if (info.name.length() == 0) {name = parameter.getParameterName();if (name == null) {throw new IllegalArgumentException("Name for argument type [" + parameter.getParameterType().getName() +"] not available, and parameter name information not found in class file either.");}}String defaultValue = (ValueConstants.DEFAULT_NONE.equals(info.defaultValue) ? null : info.defaultValue);return new NamedValueInfo(name, info.required, defaultValue);}
Yes, the exception is that I found that the name is null. I think that the name attribute of my RequestParam annotation does not exist. Is this the reason? But no. Although there is no name attribute, isn't it attractive to generate it based on the following fields? This is the case in previous tutorials. I googled this question. I agree on the Internet that ant has set the debug level and needs to be changed to on, but I didn't use ant at all. I am using tomcat of eclipse. The final conjecture is that eclipse has such a setting. Finally, it is true that there are:
. Restart and OK !!!
The problem is solved, but it is hard to understand. If so, the uncertainty is very high. What if someone else has not set it?
This is because most of the springmvc videos or tutorials are misleading. The official explanation is that the parameter names will be kept in the class file only when the debug mode is compiled, spring can then reflect and bind ......
So the name attribute must be added in the end !!!