From 6091453feb9538d014e0cf3f584c3e12d6123136 Mon Sep 17 00:00:00 2001 From: Sam Brannen <104798+sbrannen@users.noreply.github.com> Date: Thu, 3 Jul 2025 17:16:23 +0200 Subject: [PATCH] =?UTF-8?q?Introduce=20value=20alias=20for=20cacheNames=20?= =?UTF-8?q?in=20@=E2=81=A0CacheConfig?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Prior to this commit @⁠CacheConfig did not have a `value` attribute alias for `cacheNames`, even though the rest of the cache-related annotations (such as @⁠Cacheable, @⁠CachePut, etc.) do have a `value` / `cacheNames` alias pair. To address that inconsistency, this commit introduces a `value` alias for `cacheNames` in @⁠CacheConfig as well. See gh-35096 Closes gh-35152 --- .../cache/caffeine/CaffeineReactiveCachingTests.java | 2 +- .../springframework/cache/annotation/CacheConfig.java | 11 +++++++++++ .../AnnotationCacheOperationSourceTests.java | 2 +- .../cache/annotation/ReactiveCachingTests.java | 6 +++--- .../cache/config/EnableCachingIntegrationTests.java | 2 +- .../cache/interceptor/CacheErrorHandlerTests.java | 2 +- .../cache/interceptor/CachePutEvaluationTests.java | 2 +- .../interceptor/CacheResolverCustomizationTests.java | 2 +- 8 files changed, 20 insertions(+), 9 deletions(-) diff --git a/spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineReactiveCachingTests.java b/spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineReactiveCachingTests.java index ba2034c4362..cd26be375cc 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineReactiveCachingTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/caffeine/CaffeineReactiveCachingTests.java @@ -129,7 +129,7 @@ class CaffeineReactiveCachingTests { } - @CacheConfig(cacheNames = "first") + @CacheConfig("first") static class ReactiveCacheableService { private final AtomicLong counter = new AtomicLong(); diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/CacheConfig.java b/spring-context/src/main/java/org/springframework/cache/annotation/CacheConfig.java index 1521692245e..24c07634d56 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/CacheConfig.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/CacheConfig.java @@ -22,6 +22,8 @@ import java.lang.annotation.Retention; import java.lang.annotation.RetentionPolicy; import java.lang.annotation.Target; +import org.springframework.core.annotation.AliasFor; + /** * {@code @CacheConfig} provides a mechanism for sharing common cache-related * settings at the class level. @@ -39,6 +41,13 @@ import java.lang.annotation.Target; @Documented public @interface CacheConfig { + /** + * Alias for {@link #cacheNames}. + * @since 7.0 + */ + @AliasFor("cacheNames") + String[] value() default {}; + /** * Names of the default caches to consider for caching operations defined * in the annotated class. @@ -47,7 +56,9 @@ public @interface CacheConfig { * configured {@link #cacheResolver()} which typically delegates to * {@link org.springframework.cache.CacheManager#getCache}. * For further details see {@link Cacheable#cacheNames()}. + * @see #value */ + @AliasFor("value") String[] cacheNames() default {}; /** diff --git a/spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java b/spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java index a9f45200d3d..f6af1a5857f 100644 --- a/spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java +++ b/spring-context/src/test/java/org/springframework/cache/annotation/AnnotationCacheOperationSourceTests.java @@ -443,7 +443,7 @@ class AnnotationCacheOperationSourceTests { } - @CacheConfig(cacheNames = "myCache") + @CacheConfig("myCache") private interface CacheConfigIfc { @Cacheable diff --git a/spring-context/src/test/java/org/springframework/cache/annotation/ReactiveCachingTests.java b/spring-context/src/test/java/org/springframework/cache/annotation/ReactiveCachingTests.java index a7b74600953..0ba7898253c 100644 --- a/spring-context/src/test/java/org/springframework/cache/annotation/ReactiveCachingTests.java +++ b/spring-context/src/test/java/org/springframework/cache/annotation/ReactiveCachingTests.java @@ -256,7 +256,7 @@ class ReactiveCachingTests { } - @CacheConfig(cacheNames = "first") + @CacheConfig("first") static class ReactiveCacheableService { private final AtomicLong counter = new AtomicLong(); @@ -282,7 +282,7 @@ class ReactiveCachingTests { } - @CacheConfig(cacheNames = "first") + @CacheConfig("first") static class ReactiveSyncCacheableService { private final AtomicLong counter = new AtomicLong(); @@ -304,7 +304,7 @@ class ReactiveCachingTests { } - @CacheConfig(cacheNames = "first") + @CacheConfig("first") static class ReactiveFailureCacheableService { private final AtomicBoolean cacheFutureInvoked = new AtomicBoolean(); diff --git a/spring-context/src/test/java/org/springframework/cache/config/EnableCachingIntegrationTests.java b/spring-context/src/test/java/org/springframework/cache/config/EnableCachingIntegrationTests.java index f2da9f99379..2208e54bc0d 100644 --- a/spring-context/src/test/java/org/springframework/cache/config/EnableCachingIntegrationTests.java +++ b/spring-context/src/test/java/org/springframework/cache/config/EnableCachingIntegrationTests.java @@ -200,7 +200,7 @@ class EnableCachingIntegrationTests { } - @CacheConfig(cacheNames = "testCache") + @CacheConfig("testCache") static class FooServiceImpl implements FooService { private final AtomicLong counter = new AtomicLong(); diff --git a/spring-context/src/test/java/org/springframework/cache/interceptor/CacheErrorHandlerTests.java b/spring-context/src/test/java/org/springframework/cache/interceptor/CacheErrorHandlerTests.java index 926d2345d76..0446a1c1706 100644 --- a/spring-context/src/test/java/org/springframework/cache/interceptor/CacheErrorHandlerTests.java +++ b/spring-context/src/test/java/org/springframework/cache/interceptor/CacheErrorHandlerTests.java @@ -261,7 +261,7 @@ class CacheErrorHandlerTests { } - @CacheConfig(cacheNames = "test") + @CacheConfig("test") public static class SimpleService { private AtomicLong counter = new AtomicLong(); diff --git a/spring-context/src/test/java/org/springframework/cache/interceptor/CachePutEvaluationTests.java b/spring-context/src/test/java/org/springframework/cache/interceptor/CachePutEvaluationTests.java index 2884783f99c..50ad24d6f5b 100644 --- a/spring-context/src/test/java/org/springframework/cache/interceptor/CachePutEvaluationTests.java +++ b/spring-context/src/test/java/org/springframework/cache/interceptor/CachePutEvaluationTests.java @@ -121,7 +121,7 @@ class CachePutEvaluationTests { } - @CacheConfig(cacheNames = "test") + @CacheConfig("test") public static class SimpleService { private AtomicLong counter = new AtomicLong(); diff --git a/spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomizationTests.java b/spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomizationTests.java index aff99fd3165..97731324ab9 100644 --- a/spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomizationTests.java +++ b/spring-context/src/test/java/org/springframework/cache/interceptor/CacheResolverCustomizationTests.java @@ -206,7 +206,7 @@ class CacheResolverCustomizationTests { } - @CacheConfig(cacheNames = "default") + @CacheConfig("default") static class SimpleService { private final AtomicLong counter = new AtomicLong();