Spring 将配置缓存到变量 int 作为 @Cacheable 注释中的键

Spring Cache configuration to variable int as key in @Cacheable annotation

如何配置 Spring 缓存以接受 int 变量作为键?

我尝试了以下但没有奏效。我确实阅读了 API,我看到键的值必须是字符串。所以我不是 100% 确定什么是正确的配置

我尝试在我的方法中使用这个注解:

@Cacheable(cacheNames="GETREQUIREMENTPRIVATE", key = "#RequirementID")
private Requirement getRequirement(final int RequirementID, final Connection connection)

我确实在我的 ehcache.xml 文件中进行了设置:

<cache name="GETREQUIREMENTPRIVATE"
statistics="true"
         maxElementsInMemory="1000"
         eternal="true"
         memoryStoreEvictionPolicy="LFU">
</cache>

您可以使用 Integer 作为键,但不是原始的 int 应该有对象,因为获取字符串键将使用 .toString() 方法。所以 Integer,而不是 int.