我想要动态缓存名称,而 spring 4.1 允许
从 Spring 4.1 开始,缓存注解的 value 属性不再是强制性的,因为无论注解的内容如何,CacheResolver 都可以提供此特定信息。
请注意我是如何偏执地设置cacheResolver
所有可能的级别的:
@Cacheable(cacheResolver = "defaultCacheResolver")
@CacheConfig(cacheResolver = "defaultCacheResolver")
public interface GatewayRepository extends CrudRepository<Gateway, Integer> {
@Cacheable(cacheResolver = "defaultCacheResolver")
Gateway findByBulkId(int bulkId);
}
Spring 4.1.5 仍然无法通过错误验证配置:Caused by: java.lang.IllegalStateException: No cache names could be detected on 'public abstract skunkworks.data.Gateway skunkworks.repos.GatewayRepository.findByBulkId(int)'. Make sure to set the value parameter on the annotation or declare a @CacheConfig at the class-level with the default cache name(s) to use.
at org.springframework.cache.annotation.SpringCacheAnnotationParser.validateCacheOperation(SpringCacheAnnotationParser.java:240)