SoFunction
Updated on 2025-03-08

Solution to SpringBoot's failure to parse parameter parameters problem

Introduction

Use the latest versionSpringboot 3.2.1 (I use 3.2.0)When building a development environment for development, a strange error occurred when calling the interface. The main information of the error is as follows:

Name for argument of type [] not specified, and parameter name information not available via reflection. Ensure that the compiler uses the '-parameters' flag.

Cause analysis

First of all, this isSpringThe new version leads to it. Why does this problem occur? It turns out to beSpring 6.1Afterwards, the official strengthened many error checksum error notifications, and this error in this article is also one of them.

Spring means: Passing parameters in the URL must be used@PathVariableDeclare the variables used for receiving, such as:

@DeleteMapping("/employees/{employeeId}") 
public String deleteEmployee(@PathVariable int employeeId) { 
    ... 
} 
 
@PatchMapping("/employees/{id}/{firstName}") 
public String patchEmployee(@PathVariable Integer id, @PathVariable String firstName) { 
    ... 
}

The official statement has been emphasized@PathVariableThe use of   was not mentioned@RequestParam, refer to the official documentation@RequestParamYou will find a last sentence:

Note that use of @RequestParam is optional (for example, to set its attributes). By default, any argument that is a simple value type (as determined by BeanUtils#isSimpleProperty) and is not resolved by any other argument resolver, is treated as if it were annotated with @RequestParam.

Translate it roughly:

Notice@RequestParamThe use of  is optional (for example, setting its properties). By default, any parameters that are not parsed by any other parameter parser will be considered to be used.@RequestParamAnnotation.

According to the original text and translation, this naturally makes me think,@RequestParamIt can still be omitted.

However, strangely, whenSpringboot 3.2.1When using Maven to manage projects, if notspring-boot-starter-parentAs a parent project, then the interface must be explicitly declared.@RequestParam("name"), there is nothing in itnameAn error will also be reported. I clearly remember that I often omitted @RequestParam("name") in older versions of Springboot.

But if not usedspring-boot-starter-parentAs a parent project, it seems@RequestParamIt has become annotations that cannot be omitted. When you build microservices and multi-modules, you usually don't use them.spring-boot-starter-parentAs a parent project? Or is it just me not to use it? . . . It is better to try not to try the new version, as it will take less trouble

  • Error code

When there are normal parameters in the request URL, such as:http://localhost:8080/user/hello?name=zhangsan,innameAs a parameter, yoursControllerThe code is roughly as follows:

@GetMapping("/hello") 
public RespPack<?> hello(String name) { 
    return null; 
}
  • main
<dependencyManagement> 
    <dependencies> 
        <dependency> 
        <groupId></groupId> 
        <artifactId>spring-boot-dependencies</artifactId> 
        <version>${}</version> 
        <type>pom</type> 
        <scope>import</scope> 
        </dependency> 
    </dependencies> 
</dependencyManagement> 
<dependencies> 
    <dependency> 
        <groupId></groupId> 
        <artifactId>spring-boot-starter-web</artifactId> 
    </dependency> 
</dependencies>

solve

I don't know if this phenomenon is an official bug, but I have found two solutions:

  • Use on parameters@RequestParam("name")
  • usespring-boot-starter-parent
&lt;!-- Willspring-boot-starter-parentIntroduced as parent project --&gt; 
&lt;parent&gt; 
    &lt;groupId&gt;&lt;/groupId&gt; 
    &lt;artifactId&gt;spring-boot-starter-parent&lt;/artifactId&gt; 
    &lt;version&gt;3.2.1&lt;/version&gt; 
    &lt;relativePath/&gt; 
&lt;/parent&gt;
  • maven-compiler-plugin
    Netizen's removal solution: Fatherpom or itself pomAdd tomaven-compiler-pluginConfiguration:
<build> 
    <plugin> 
    <groupId></groupId> 
    <artifactId>maven-compiler-plugin</artifactId> 
    <configuration> 
        <parameters>true</parameters> 
    </configuration> 
    </plugin>
</build> 

This ensures use-parametersFlags compile the code so that the parameter name is available at runtime.

This is the end of this article about the solution to the problem of SpringBoot's inability to parse parameter parameters. For more related content related to SpringBoot's inability to parse parameter, please search for my previous articles or continue browsing the related articles below. I hope everyone will support me in the future!