I am using the @RequestParam annotation to get the request parameters , and using the same to insert the values into the DB. I have setup the controller to re-direct to the same page which contains the text fields for the user to enter the values, which are being read using the @RequestParam annotation.
But after I enter the values into the text fields , and click submit , it throws this error
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.
I am a newbie to Spring 3 , and unable to understand the error. Can anybody please shed light on the same.
Thanks in advance, Vivek
In Spring MVC, the @RequestParam annotation is used to read the form data and bind it automatically to the parameter present in the provided method. So, it ignores the requirement of HttpServletRequest object to read the provided data.
@RequestParam is a Spring annotation used to bind a web request parameter to a method parameter. It has the following optional elements: defaultValue - used as a fallback when the request parameter is not provided or has an empty value. name - name of the request parameter to bind to.
Method parameters annotated with @RequestParam are required by default. will correctly invoke the method. When the parameter isn't specified, the method parameter is bound to null.
2) @RequestParam is more useful on a traditional web application where data is mostly passed in the query parameters while @PathVariable is more suitable for RESTful web services where URL contains values.
In order to inject the value of request parameter into your handler method parameter, either one of the following should be satisfied
The name of the request parameter must match the name of the method parameter. e.g. Following will inject the request parameter named "studentName" into the method parameter studentName
public String goToStep(@RequestParam String studentName)
The request parameter name must be explicitly specified if it does not match the method parameter. The following will inject "nameOfStudent" request parameter into studentName:
public String goToStep(@RequestParam("nameOfStudent") String studentName)
Please post your handler method code if your issue continues to persist.
I asked for the version you are using because I ran with a similar problem a few days ago. I was using Spring 3.1.0.M2 and the same exception appeared when I was using @PathVariable in proxied @Controller.
It was caused by a resolved known bug. You just have to switch to 3.0.6 or try the nightly build 3.1.0.BUILD-SNAPSHOT. Of course, the latter option is not recommended for production environment.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With