缓存操作返回空键,参数名称信息无法通过反射获得。确保使用“-parameters”编译器标志

问题描述 投票:0回答:1

将我们的应用程序更新到 Spring Boot 3.2.5 和 Spring Framework 6.1.6。我们收到以下错误。

ERROR c.a.s.t.c.e.ControllerExceptionHandler - java.lang.IllegalArgumentException: 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.
java.lang.IllegalArgumentException: 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.
ERROR c.a.s.t.c.e.ControllerExceptionHandler - java.lang.IllegalArgumentException: Null key returned for cache operation  caches=[cacheExample] | key='#cacheKey' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='true']. If you are using named parameters, ensure that the compiler uses the '-parameters' flag.
java.lang.IllegalArgumentException: Null key returned for cache operation  caches=[cacheExample] | key='#cacheKey' | keyGenerator='' | cacheManager='' | cacheResolver='' | condition='' | unless='' | sync='true']. If you are using named parameters, ensure that the compiler uses the '-parameters' flag.

它接缝,它要求使用“-parameters”标志编译(java)代码。因此,我按照 https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-6.x#parameter-name-retention:

上的说明进行操作

我已添加:

tasks.withType(JavaCompile).configureEach {
    options.compilerArgs.add("-parameters")
}

即使我尝试添加线程中提到的以下内容:https://github.com/spring-projects/spring-framework/issues/31729

tasks.withType(JavaCompile) {
    configure(options) {
        options.compilerArgs << '-parameters'
    }
}

没有什么对我有用。但是,是的,添加像

key="#p0"
这样的参数索引对我来说很有效。实际上,我想使用参数名称而不是参数索引。

我使用了以下配置/工具:

  1. springBoot版本=3.2.5
  2. springFramework版本=6.1.6
  3. Java=17.0.5
  4. gradle=8.7
  5. Vscode=1.88.1

您能帮我解决这个问题吗?

spring spring-boot
1个回答
0
投票

这对我有用:

tasks.withType(JavaCompile).configureEach {
    options.encoding = 'UTF-8'
    options.compilerArgs.add("-parameters")
}
© www.soinside.com 2019 - 2024. All rights reserved.