SpringMVC新版本踩坑[已解决]

devtools/2025/2/22 9:40:30/

问题:

在使用最新版本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.ppmy.cn/devtools/160269.html

相关文章

fastapi+vue实现按钮级别的权限控制

一、前端部分 1.1 自定义指令 import store from /store// 判断是否有权限 const hasPermission (value, el) > {// 检查是否配置了权限参数if (!Array.isArray(value) || value.length 0) {throw new Error(v-permission 需要配置权限&#xff0c;例如 v-permission&qu…

iOS App的启动与优化

App的启动流程 App启动分为冷启动和热启动 冷启动&#xff1a;从0开始启动App热启动&#xff1a;App已经在内存中&#xff0c;但是后台还挂着&#xff0c;再次点击图标启动App。 一般对App启动的优化都是针对冷启动。 App冷启动可分为三个阶段&#xff1a; dyld&#xff1a…

【R语言】主成分分析与因子分析

一、主成分分析 主成分分析&#xff08;Principal Component Analysis, PCA&#xff09;是一种常用的无监督数据降维技术&#xff0c;广泛应用于统计学、数据科学和机器学习等领域。它通过正交化线性变换将&#xff08;高维&#xff09;原始数据投影到一个新的坐标系&#xff…

oracle序列每天重置

在Oracle数据库中&#xff0c;若要实现序列每天重置&#xff0c;可以通过以下步骤进行操作&#xff1a; 一、创建序列 首先&#xff0c;需要创建一个序列。创建序列的SQL语句如下&#xff1a; CREATE SEQUENCE sequence_name START WITH 0 -- 或其他起始值 INCREMENT BY 1 CA…

【Vue】集成Antlr4

1.下载.g4文件 下载地址&#xff1a;https://download.csdn.net/download/qq_42454367/90396095 2.安装Antlr &#xff08;1&#xff09;使用以下命令安装依赖 pnpm install antlr4ng pnpm install --save-dev antlr4ng-cli&#xff08;2&#xff09;在package.json文件中配…

【产品资料】陀螺匠·企业助手v1.8 产品介绍

陀螺匠企业助手是一套采用Laravel 9框架结合Swoole高性能协程服务与Vue.js前端技术栈构建的新型智慧企业管理与运营系统。该系统深度融合了客户管理、项目管理、审批流程自动化以及低代码开发平台&#xff0c;旨在为企业提供一站式、数字化转型的全方位解决方案&#xff0c;助力…

调用DeepSeek API接口:实现智能数据挖掘与分析

调用DeepSeek API接口:实现智能数据挖掘与分析 在当今数据驱动的时代,企业和开发者越来越依赖高效的数据挖掘与分析工具来获取有价值的洞察。DeepSeek作为一款先进的智能数据挖掘平台,提供了强大的API接口,帮助用户轻松集成其功能到自己的应用中。本文将详细介绍如何调用D…

【前端框架】深入探讨 Vue 3 组件生命周期的变化和最佳实践

一、Vue 3 组件生命周期的变化 1. 生命周期钩子的更名与调整 在 Vue 2 中&#xff0c;组件生命周期钩子包括 beforeCreate、created、beforeMount、mounted、beforeUpdate、updated、beforeDestroy 和 destroyed。而在 Vue 3 中&#xff0c;部分钩子进行了更名&#xff0c;以…