SpringMVC新版本踩坑[已办理]

打印 上一主题 下一主题

主题 890|帖子 890|积分 2670

问题:

在使用最新版本springMVC做项目部署时,浏览器反复500,如下图:

非常形貌:
范例非常陈诉
消息Request processing failed: java.lang.IllegalArgumentException: Name for argument of type [int] 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 [int] 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 [int] 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 编译器标记:
根据提示,想着试下在编译时做一个配置:

但是在尝试后并未发现有作用,于是继续探求其他办理方法。
尝试二,在项目pom.xml文件中配置插件:
  1. <build>
  2.         <plugins>
  3.             <plugin>
  4.                 <groupId>org.apache.maven.plugins</groupId>
  5.                 <artifactId>maven-compiler-plugin</artifactId>
  6.                 <version>3.13.0</version>
  7.                 <configuration>
  8.                     <parameters>true</parameters>
  9.                     <source>22</source>
  10.                     <target>22</target>
  11.                     <encoding>UTF-8</encoding>
  12.                     <!-- 启用 -parameters 编译器标志 -->
  13.                     <compilerArgument>-parameters</compilerArgument>
  14.                 </configuration>
  15.             </plugin>
  16.         </plugins>
  17.     </build>
复制代码
大部门场景这个设置生效的,但是进行测试后,发现仍旧没有用。
尝试三,给参数注解@PathVariable加上value属性:
原代码:
  1. public Type test(@PathVariable int var1, @PathVariable int var2){
  2.         ...
  3.         return type;
  4.     }
复制代码
修改后代码:
  1. ?
  2. public Type test(@PathVariable(value ="var1") int var1, @PathVariable(value ="var2") int var2){
  3.         ...
  4.         return type;
  5.     }
  6. ?
复制代码
尝试测试,终于看到了久违的200:

至此,终于在各种尝试中办理了问题。
总结:在做参数传递时,需要多把稳@PathVariable注解的使用,有时严格按照其使用方法也许是一个好的习惯。
参考文章:升级springboot3.2.0报Name for argument of type [java.lang.String] not specified, and parameter name inf-CSDN博客
【已办理】java.lang.IllegalArgumentException: Name for argument of type [java.lang.Integer] not specified-CSDN博客
springMvc:Request processing failed: java.lang.IllegalArgumentException: Name for argument of type [java.lang.String] not specified, and parameter name information not available via reflectio… - 困到很想醒 - 博客园
感谢以上大佬。

免责声明:如果侵犯了您的权益,请联系站长,我们会及时删除侵权内容,谢谢合作!更多信息从访问主页:qidao123.com:ToB企服之家,中国第一个企服评测及商务社交产业平台。

本帖子中包含更多资源

您需要 登录 才可以下载或查看,没有账号?立即注册

x
回复

使用道具 举报

0 个回复

倒序浏览

快速回复

您需要登录后才可以回帖 登录 or 立即注册

本版积分规则

杀鸡焉用牛刀

金牌会员
这个人很懒什么都没写!

标签云

快速回复 返回顶部 返回列表