Name for arguent type [java.lang.String] not available, and parameter name information not found 的解决
1 问题表现
在读书籍《Spring in Action》1第4版第5章的例子时,遵照该章的源代码运行,得到异常报告如下:
Request processing failed; nested exception is java.lang.IllegalArgumentException: Name for arguent type [java.lang.String] not available, and parameter name information not found in class file either.
具体截图如下:

我用的环境为:

Java版本为1.8。
2 解决
将SpitterController.java代码中的函数showSpitterProfile()中的**@PathVariable改为@PathVariable(“username”)**,重新编译运行,即可成功,如下图:

3 原因分析
该书上讲解为:
Because the method parameter name happens to be the same as the placeholder name, you can optionally omit the value parameter on @PathVariable
亦即,value后的名称与该函数中使用的参数名称一样的话话,在@PathVariable后的名字可以省略,但从我的环境运行来看,该名字省略了会出错,尽管书上代码基于的环境也是Spring 4。
我认为,书上讲解的不一定是错的。具体的原因可能是所用环境的版本的细微差别所致。
4 总结
在读一些相对旧的书籍时,一定要开动脑筋,多多思考,边运行代码边读书。这是很显然的,关键是否能做到。
Craig Walls. Spring in Action. 4th Edition. Shelter Island, NY: Manning Publications, 2015, pp131-163. ↩︎
更多推荐


所有评论(0)