Skip to content

Commit 8422d9d

Browse files
committed
Add default methods to CachingConfigurer
This commit adds default methods to CachingConfigurer and JCacheConfigurer and removes the reference to their respective support classes as they are now irrelevant. Closes gh-27811
1 parent c50a509 commit 8422d9d

File tree

14 files changed

+59
-53
lines changed

14 files changed

+59
-53
lines changed

spring-context-support/src/main/java/org/springframework/cache/jcache/config/JCacheConfigurer.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,8 +26,7 @@
2626
* <p>To be implemented by classes annotated with
2727
* {@link org.springframework.cache.annotation.EnableCaching} that wish
2828
* or need to specify explicitly how exception caches are resolved for
29-
* annotation-driven cache management. Consider extending {@link JCacheConfigurerSupport},
30-
* which provides a stub implementation of all interface methods.
29+
* annotation-driven cache management.
3130
*
3231
* <p>See {@link org.springframework.cache.annotation.EnableCaching} for
3332
* general examples and context; see {@link #exceptionCacheResolver()} for
@@ -36,7 +35,6 @@
3635
* @author Stephane Nicoll
3736
* @since 4.1
3837
* @see CachingConfigurer
39-
* @see JCacheConfigurerSupport
4038
* @see org.springframework.cache.annotation.EnableCaching
4139
*/
4240
public interface JCacheConfigurer extends CachingConfigurer {
@@ -60,6 +58,8 @@ public interface JCacheConfigurer extends CachingConfigurer {
6058
* See {@link org.springframework.cache.annotation.EnableCaching} for more complete examples.
6159
*/
6260
@Nullable
63-
CacheResolver exceptionCacheResolver();
61+
default CacheResolver exceptionCacheResolver() {
62+
return null;
63+
}
6464

6565
}

spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheAnnotationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@
2626
import org.junit.jupiter.api.Test;
2727

2828
import org.springframework.beans.factory.annotation.Autowired;
29-
import org.springframework.cache.annotation.CachingConfigurerSupport;
29+
import org.springframework.cache.annotation.CachingConfigurer;
3030
import org.springframework.cache.annotation.EnableCaching;
3131
import org.springframework.cache.interceptor.KeyGenerator;
3232
import org.springframework.cache.interceptor.SimpleKeyGenerator;
@@ -104,7 +104,7 @@ public void testEvictAllEarlyWithTransaction() {
104104

105105
@Configuration
106106
@EnableCaching
107-
static class EnableCachingConfig extends CachingConfigurerSupport {
107+
static class EnableCachingConfig implements CachingConfigurer {
108108

109109
@Autowired
110110
CachingProvider cachingProvider;

spring-context-support/src/test/java/org/springframework/cache/jcache/config/JCacheJavaConfigTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -180,7 +180,7 @@ public CacheResolver exceptionCacheResolver() {
180180

181181
@Configuration
182182
@EnableCaching
183-
public static class EmptyConfigSupportConfig extends JCacheConfigurerSupport {
183+
public static class EmptyConfigSupportConfig implements JCacheConfigurer {
184184
@Bean
185185
public CacheManager cm() {
186186
return new NoOpCacheManager();
@@ -190,7 +190,7 @@ public CacheManager cm() {
190190

191191
@Configuration
192192
@EnableCaching
193-
static class FullCachingConfigSupport extends JCacheConfigurerSupport {
193+
static class FullCachingConfigSupport implements JCacheConfigurer {
194194

195195
@Override
196196
@Bean
@@ -220,7 +220,7 @@ public CacheResolver exceptionCacheResolver() {
220220

221221
@Configuration
222222
@EnableCaching
223-
static class NoExceptionCacheResolverConfig extends JCacheConfigurerSupport {
223+
static class NoExceptionCacheResolverConfig implements JCacheConfigurer {
224224

225225
@Override
226226
@Bean

spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheErrorHandlerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@
3434
import org.springframework.cache.annotation.EnableCaching;
3535
import org.springframework.cache.interceptor.CacheErrorHandler;
3636
import org.springframework.cache.interceptor.SimpleKeyGenerator;
37-
import org.springframework.cache.jcache.config.JCacheConfigurerSupport;
37+
import org.springframework.cache.jcache.config.JCacheConfigurer;
3838
import org.springframework.cache.support.SimpleCacheManager;
3939
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
4040
import org.springframework.context.annotation.Bean;
@@ -141,7 +141,7 @@ public void clearFail() {
141141

142142
@Configuration
143143
@EnableCaching
144-
static class Config extends JCacheConfigurerSupport {
144+
static class Config implements JCacheConfigurer {
145145

146146
@Bean
147147
@Override

spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheKeyGeneratorTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -34,7 +34,7 @@
3434
import org.springframework.cache.interceptor.KeyGenerator;
3535
import org.springframework.cache.interceptor.SimpleKey;
3636
import org.springframework.cache.interceptor.SimpleKeyGenerator;
37-
import org.springframework.cache.jcache.config.JCacheConfigurerSupport;
37+
import org.springframework.cache.jcache.config.JCacheConfigurer;
3838
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
3939
import org.springframework.context.annotation.Bean;
4040
import org.springframework.context.annotation.Configuration;
@@ -97,7 +97,7 @@ public void getFiltered() {
9797

9898
@Configuration
9999
@EnableCaching
100-
static class Config extends JCacheConfigurerSupport {
100+
static class Config implements JCacheConfigurer {
101101

102102
@Bean
103103
@Override
@@ -151,7 +151,7 @@ private void expect(Object... params) {
151151
@Override
152152
public Object generate(Object target, Method method, Object... params) {
153153
assertThat(Arrays.equals(expectedParams, params)).as("Unexpected parameters: expected: "
154-
+ Arrays.toString(this.expectedParams) + " but got: " + Arrays.toString(params)).isTrue();
154+
+ Arrays.toString(this.expectedParams) + " but got: " + Arrays.toString(params)).isTrue();
155155
return new SimpleKey(params);
156156
}
157157
}

spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2018 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,8 +26,7 @@
2626
* Interface to be implemented by @{@link org.springframework.context.annotation.Configuration
2727
* Configuration} classes annotated with @{@link EnableCaching} that wish or need to
2828
* specify explicitly how caches are resolved and how keys are generated for annotation-driven
29-
* cache management. Consider extending {@link CachingConfigurerSupport}, which provides a
30-
* stub implementation of all interface methods.
29+
* cache management.
3130
*
3231
* <p>See @{@link EnableCaching} for general examples and context; see
3332
* {@link #cacheManager()}, {@link #cacheResolver()} and {@link #keyGenerator()}
@@ -37,7 +36,6 @@
3736
* @author Stephane Nicoll
3837
* @since 3.1
3938
* @see EnableCaching
40-
* @see CachingConfigurerSupport
4139
*/
4240
public interface CachingConfigurer {
4341

@@ -64,7 +62,9 @@ public interface CachingConfigurer {
6462
* See @{@link EnableCaching} for more complete examples.
6563
*/
6664
@Nullable
67-
CacheManager cacheManager();
65+
default CacheManager cacheManager() {
66+
return null;
67+
}
6868

6969
/**
7070
* Return the {@link CacheResolver} bean to use to resolve regular caches for
@@ -89,7 +89,9 @@ public interface CachingConfigurer {
8989
* See {@link EnableCaching} for more complete examples.
9090
*/
9191
@Nullable
92-
CacheResolver cacheResolver();
92+
default CacheResolver cacheResolver() {
93+
return null;
94+
}
9395

9496
/**
9597
* Return the key generator bean to use for annotation-driven cache management.
@@ -110,7 +112,9 @@ public interface CachingConfigurer {
110112
* See @{@link EnableCaching} for more complete examples.
111113
*/
112114
@Nullable
113-
KeyGenerator keyGenerator();
115+
default KeyGenerator keyGenerator() {
116+
return null;
117+
}
114118

115119
/**
116120
* Return the {@link CacheErrorHandler} to use to handle cache-related errors.
@@ -133,6 +137,8 @@ public interface CachingConfigurer {
133137
* See @{@link EnableCaching} for more complete examples.
134138
*/
135139
@Nullable
136-
CacheErrorHandler errorHandler();
140+
default CacheErrorHandler errorHandler() {
141+
return null;
142+
}
137143

138144
}

spring-context/src/test/java/org/springframework/cache/CacheReproTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2020 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@
2828
import org.springframework.cache.annotation.CachePut;
2929
import org.springframework.cache.annotation.Cacheable;
3030
import org.springframework.cache.annotation.Caching;
31-
import org.springframework.cache.annotation.CachingConfigurerSupport;
31+
import org.springframework.cache.annotation.CachingConfigurer;
3232
import org.springframework.cache.annotation.EnableCaching;
3333
import org.springframework.cache.concurrent.ConcurrentMapCache;
3434
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
@@ -306,7 +306,7 @@ public Object getNeverCache(String key) {
306306

307307
@Configuration
308308
@EnableCaching
309-
public static class Spr13081Config extends CachingConfigurerSupport {
309+
public static class Spr13081Config implements CachingConfigurer {
310310

311311
@Bean
312312
@Override

spring-context/src/test/java/org/springframework/cache/config/EnableCachingIntegrationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -26,7 +26,7 @@
2626
import org.springframework.cache.CacheManager;
2727
import org.springframework.cache.annotation.CacheConfig;
2828
import org.springframework.cache.annotation.Cacheable;
29-
import org.springframework.cache.annotation.CachingConfigurerSupport;
29+
import org.springframework.cache.annotation.CachingConfigurer;
3030
import org.springframework.cache.annotation.EnableCaching;
3131
import org.springframework.context.ConfigurableApplicationContext;
3232
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
@@ -124,7 +124,7 @@ private Cache getCache() {
124124

125125

126126
@Configuration
127-
static class SharedConfig extends CachingConfigurerSupport {
127+
static class SharedConfig implements CachingConfigurer {
128128

129129
@Override
130130
@Bean

spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
2323
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
2424
import org.springframework.cache.CacheManager;
25-
import org.springframework.cache.annotation.CachingConfigurerSupport;
25+
import org.springframework.cache.annotation.CachingConfigurer;
2626
import org.springframework.cache.annotation.EnableCaching;
2727
import org.springframework.cache.interceptor.CacheErrorHandler;
2828
import org.springframework.cache.interceptor.CacheInterceptor;
@@ -150,7 +150,7 @@ public void bothSetOnlyResolverIsUsed() {
150150

151151
@Configuration
152152
@EnableCaching
153-
static class EnableCachingConfig extends CachingConfigurerSupport {
153+
static class EnableCachingConfig implements CachingConfigurer {
154154

155155
@Override
156156
@Bean
@@ -227,7 +227,7 @@ public CacheManager cm2() {
227227

228228
@Configuration
229229
@EnableCaching
230-
static class MultiCacheManagerConfigurer extends CachingConfigurerSupport {
230+
static class MultiCacheManagerConfigurer implements CachingConfigurer {
231231

232232
@Bean
233233
public CacheManager cm1() {
@@ -253,7 +253,7 @@ public KeyGenerator keyGenerator() {
253253

254254
@Configuration
255255
@EnableCaching
256-
static class EmptyConfigSupportConfig extends CachingConfigurerSupport {
256+
static class EmptyConfigSupportConfig implements CachingConfigurer {
257257

258258
@Bean
259259
public CacheManager cm() {
@@ -264,7 +264,7 @@ public CacheManager cm() {
264264

265265
@Configuration
266266
@EnableCaching
267-
static class FullCachingConfig extends CachingConfigurerSupport {
267+
static class FullCachingConfig implements CachingConfigurer {
268268

269269
@Override
270270
@Bean

spring-context/src/test/java/org/springframework/cache/config/ExpressionCachingIntegrationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2016 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -20,7 +20,7 @@
2020

2121
import org.springframework.cache.CacheManager;
2222
import org.springframework.cache.annotation.CachePut;
23-
import org.springframework.cache.annotation.CachingConfigurerSupport;
23+
import org.springframework.cache.annotation.CachingConfigurer;
2424
import org.springframework.cache.annotation.EnableCaching;
2525
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
2626
import org.springframework.context.ConfigurableApplicationContext;
@@ -122,7 +122,7 @@ public String getId() {
122122

123123
@Configuration
124124
@EnableCaching
125-
static class SharedConfig extends CachingConfigurerSupport {
125+
static class SharedConfig implements CachingConfigurer {
126126

127127
@Override
128128
@Bean

spring-context/src/test/java/org/springframework/cache/interceptor/CacheErrorHandlerTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,7 +28,7 @@
2828
import org.springframework.cache.annotation.CacheEvict;
2929
import org.springframework.cache.annotation.CachePut;
3030
import org.springframework.cache.annotation.Cacheable;
31-
import org.springframework.cache.annotation.CachingConfigurerSupport;
31+
import org.springframework.cache.annotation.CachingConfigurer;
3232
import org.springframework.cache.annotation.EnableCaching;
3333
import org.springframework.cache.support.SimpleCacheManager;
3434
import org.springframework.cache.support.SimpleValueWrapper;
@@ -170,7 +170,7 @@ public void clearFailProperException() {
170170

171171
@Configuration
172172
@EnableCaching
173-
static class Config extends CachingConfigurerSupport {
173+
static class Config implements CachingConfigurer {
174174

175175
@Bean
176176
@Override

spring-context/src/test/java/org/springframework/cache/interceptor/CachePutEvaluationTests.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2019 the original author or authors.
2+
* Copyright 2002-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -27,7 +27,7 @@
2727
import org.springframework.cache.annotation.CacheConfig;
2828
import org.springframework.cache.annotation.CachePut;
2929
import org.springframework.cache.annotation.Cacheable;
30-
import org.springframework.cache.annotation.CachingConfigurerSupport;
30+
import org.springframework.cache.annotation.CachingConfigurer;
3131
import org.springframework.cache.annotation.EnableCaching;
3232
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
3333
import org.springframework.context.ConfigurableApplicationContext;
@@ -106,7 +106,7 @@ public void getAndPut() {
106106

107107
@Configuration
108108
@EnableCaching
109-
static class Config extends CachingConfigurerSupport {
109+
static class Config implements CachingConfigurer {
110110

111111
@Bean
112112
@Override

0 commit comments

Comments
 (0)