版本
spring-boot:3.2.1
现象
项目parent没有使用spring-boot-starter-parent
使用@Cacheable注解方法,key设置为方法参数名时报错如下:
Caused by: java.lang.IllegalArgumentException: Null key returned for cache operation [Builder[…使用@Cacheable注解的方法] caches=[…] | key=‘#方法参数名’ | keyGenerator=‘’ | cacheManager=‘’ | cacheResolver=‘’ | condition=‘’ | unless=‘’ | sync=‘false’]. If you are using named parameters, ensure that the compiler uses the ‘-parameters’ flag.
解决
pom.xml 添加配置,maven编译时保留参数名
代码语言:javascript复制<build>
<pluginManagement>
<plugins>
<plugin>
<groupId>org.apache.maven.plugins</groupId>
<artifactId>maven-compiler-plugin</artifactId>
<configuration>
<parameters>true</parameters>
</configuration>
</plugin>
...