I’m encountering an issue with Spring Boot. Recently, I upgraded the Spring Boot dependency to version 3.2.4.
When I attempt to call the following endpoint:
@PutMapping("/{uid}/test/{state}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void update(
Context context,
@PathVariable String uid,
@PathVariable String state
) throws RuntimeFunctionalException {
this.service.updateState(uid, state, context);
}
Output:
Name for argument of type [java.lang.String] not specified, and parameter name information not available via reflection. Ensure that the compiler uses the ‘-parameters’ flag
Is anyone else facing the same issue?
To fix the problem, add name for @RequestParam
and @PathVariable
annotations.
So, instead of this:
public ResponseEntity<CommandResponse> update(
@PathVariable long param1,
@RequestParam String param2) {
// ...
}
use this >>>
public ResponseEntity<CommandResponse> update(
@PathVariable("param1") long param1,
@RequestParam("param2") String param2) {
// ...
}
0
Please include this configuration in your POM file
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<parameters>true</parameters>
</configuration>
</plugin>
this configuration is important <parameters>true</parameters>
For more details use this link
I got the same error as you. What I found out that is you really need to add the ‘-parameters’ option to Java compiler.
Depending on your build tool, you should take correct actions. Like in my case, I’m using Gradle, here is what it looks like:
tasks.withType(JavaCompile) {
options.compilerArgs = ['-parameters']
doFirst {
println "Compiler args: ${options.compilerArgs}"
}}
Additionally, I use VS Code, and when I run the Application file using the Run Java (when right click), it’s not working. Using the ./gradlew bootRun
works as expected!
And one more thing, if you use explicit PathVariable, it should work.
I got the same error when launching tests in VS Code. Seems close problem to to Nix_snow_cat’s answer above.
There is an option in Java: Runtime configuration / Compiler where it’s possible to turn on storing parameters information (seems that with this option VS Code will compile with –parameters option).
After setting it on – tests started to execute properly in vs code.
Java: Runtime configuration -> Compiler -> [x] Store information about method parameters .