SpringMVC新版本踩坑[已办理]
问题:在使用最新版本springMVC做项目部署时,浏览器反复500,如下图:
https://i-blog.csdnimg.cn/direct/333266341c3446b1a50a501a8c5bb9c7.jpeg
非常形貌:
范例非常陈诉
消息Request processing failed: java.lang.IllegalArgumentException: Name for argument of type not specified, and parameter name information not available via reflection. Ensure that the compiler uses the ‘-parameters’ flag.
形貌服务器碰到一个不测的情况,克制它完成请求。
破例情况
jakarta.servlet.ServletException: Request processing failed: java.lang.IllegalArgumentException: Name for argument of type not specified, and parameter name information not available via reflection. Ensure that the compiler uses the ‘-parameters’ flag.
根本缘故因由。
java.lang.IllegalArgumentException: Name for argument of type not specified, and parameter name information not available via reflection. Ensure that the compiler uses the ‘-parameters’ flag.
问题出现缘故因由:新版本Spring调整了参数
找了一晚上问题地点,发现可能是新版本调整了参数,而spring会主动帮助设置,导致编译时选项“-参数”被禁用。也就是错误信息中的末了提示:Ensure that the compiler uses the ‘-parameters’ flag.
尝试一,在idea编译器中设置指定参数,启用 -parameters 编译器标记:
根据提示,想着试下在编译时做一个配置:
https://i-blog.csdnimg.cn/direct/a295f6b7ea67469cbac3220fd148cf13.png
但是在尝试后并未发现有作用,于是继续探求其他办理方法。
尝试二,在项目pom.xml文件中配置插件:
<build>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<version>3.13.0</version>
<configuration>
<parameters>true</parameters>
<source>22</source>
<target>22</target>
<encoding>UTF-8</encoding>
<!-- 启用 -parameters 编译器标志 -->
<compilerArgument>-parameters</compilerArgument>
</configuration>
</plugin>
</plugins>
</build>
大部门场景这个设置生效的,但是进行测试后,发现仍旧没有用。
尝试三,给参数注解@PathVariable加上value属性:
原代码:
public Type test(@PathVariable int var1, @PathVariable int var2){
...
return type;
}
修改后代码:
?
public Type test(@PathVariable(value ="var1") int var1, @PathVariable(value ="var2") int var2){
...
return type;
}
?
尝试测试,终于看到了久违的200:
https://i-blog.csdnimg.cn/direct/9f7ca3b9fb7c40eca1d9bbfd6e863dc7.png
至此,终于在各种尝试中办理了问题。
总结:在做参数传递时,需要多把稳@PathVariable注解的使用,有时严格按照其使用方法也许是一个好的习惯。
参考文章:升级springboot3.2.0报Name for argument of type not specified, and parameter name inf-CSDN博客
【已办理】java.lang.IllegalArgumentException: Name for argument of type not specified-CSDN博客
springMvc:Request processing failed: java.lang.IllegalArgumentException: Name for argument of type not specified, and parameter name information not available via reflectio… - 困到很想醒 - 博客园
感谢以上大佬。
免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。
页:
[1]