当前位置: 首页 > news >正文

SpringMVC新版本踩坑[已解决]

问题:

在使用最新版本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文件中配置插件:

<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:

至此,终于在各种尝试中解决了问题。

总结:在做参数传递时,需要多留心@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… - 困到很想醒 - 博客园

感谢以上大佬。

http://www.lryc.cn/news/537428.html

相关文章:

  • 一款利器提升 StarRocks 表结构设计效率
  • 老牌软件,如今依旧坚挺
  • Plaid | 数据库切换历程:从 AWS Aurora MySQL 到 TiDB 的迁移之旅
  • MongoDB 扩缩容实战:涵盖节点配置、服务启动与移除操作
  • Python学习心得字符串拼接的几种方法
  • USB2.03.0摄像头区分UVC相机在linux中的常用命令
  • electron 学习
  • 美术教程2025
  • CPT205 计算机图形学 OpenGL 3D实践(CW2)
  • 基于单片机的开关电源设计(论文+源码)
  • autogen_core中的DataclassJsonMessageSerializer类
  • floodfill算法系列一>太平洋大西洋水流问题
  • DeepSeek 助力 Vue 开发:打造丝滑的无限滚动(Infinite Scroll)
  • JavaScript 内置对象-Math对象
  • 硕成C语言22【一些算法和数组的概念】
  • Halcon相机标定
  • 部门管理(体验,最原始方法来做,Django+mysql)
  • clickhouse集群搭建
  • 250214-java类集框架
  • 二叉树(C语言版)
  • ASP.NET Core 面试宝典【刷题系列】
  • 案例-02.部门管理-查询
  • src和href区别
  • Java每日精进·45天挑战·Day19
  • 区块链的交易管理和共识机制
  • 最新国内 ChatGPT Plus/Pro 获取教程
  • Apollo 9.0 速度动态规划决策算法 – path time heuristic optimizer
  • Apache Iceberg 与 Apache Hudi:数据湖领域的双雄对决
  • 【LeetCode Hot100 普通数组】最大子数组和、合并区间、旋转数组、除自身以外数组的乘积、缺失的第一个正整数
  • 共享存储-一步一步部署ceph分布式文件系统