From 8422d9d22f4156831a92b5e01950306880135c0f Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 14 Dec 2021 13:44:48 +0100 Subject: [PATCH 1/2] 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 --- .../cache/jcache/config/JCacheConfigurer.java | 10 ++++----- .../jcache/JCacheEhCacheAnnotationTests.java | 6 ++--- .../jcache/config/JCacheJavaConfigTests.java | 8 +++---- .../interceptor/JCacheErrorHandlerTests.java | 6 ++--- .../interceptor/JCacheKeyGeneratorTests.java | 8 +++---- .../cache/annotation/CachingConfigurer.java | 22 ++++++++++++------- .../cache/CacheReproTests.java | 6 ++--- .../config/EnableCachingIntegrationTests.java | 6 ++--- .../cache/config/EnableCachingTests.java | 10 ++++----- .../ExpressionCachingIntegrationTests.java | 6 ++--- .../interceptor/CacheErrorHandlerTests.java | 6 ++--- .../interceptor/CachePutEvaluationTests.java | 6 ++--- .../CacheResolverCustomizationTests.java | 6 ++--- .../interceptor/CacheSyncFailureTests.java | 6 ++--- 14 files changed, 59 insertions(+), 53 deletions(-) diff --git a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/JCacheConfigurer.java b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/JCacheConfigurer.java index 989e720aeb9..039729a02d5 100644 --- a/spring-context-support/src/main/java/org/springframework/cache/jcache/config/JCacheConfigurer.java +++ b/spring-context-support/src/main/java/org/springframework/cache/jcache/config/JCacheConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,7 @@ import org.springframework.lang.Nullable; *

To be implemented by classes annotated with * {@link org.springframework.cache.annotation.EnableCaching} that wish * or need to specify explicitly how exception caches are resolved for - * annotation-driven cache management. Consider extending {@link JCacheConfigurerSupport}, - * which provides a stub implementation of all interface methods. + * annotation-driven cache management. * *

See {@link org.springframework.cache.annotation.EnableCaching} for * general examples and context; see {@link #exceptionCacheResolver()} for @@ -36,7 +35,6 @@ import org.springframework.lang.Nullable; * @author Stephane Nicoll * @since 4.1 * @see CachingConfigurer - * @see JCacheConfigurerSupport * @see org.springframework.cache.annotation.EnableCaching */ public interface JCacheConfigurer extends CachingConfigurer { @@ -60,6 +58,8 @@ public interface JCacheConfigurer extends CachingConfigurer { * See {@link org.springframework.cache.annotation.EnableCaching} for more complete examples. */ @Nullable - CacheResolver exceptionCacheResolver(); + default CacheResolver exceptionCacheResolver() { + return null; + } } diff --git a/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheAnnotationTests.java b/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheAnnotationTests.java index 188cc293c97..e73dd79a222 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheAnnotationTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/jcache/JCacheEhCacheAnnotationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Test; import org.springframework.beans.factory.annotation.Autowired; -import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.CachingConfigurer; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.interceptor.KeyGenerator; import org.springframework.cache.interceptor.SimpleKeyGenerator; @@ -104,7 +104,7 @@ public class JCacheEhCacheAnnotationTests extends AbstractCacheAnnotationTests { @Configuration @EnableCaching - static class EnableCachingConfig extends CachingConfigurerSupport { + static class EnableCachingConfig implements CachingConfigurer { @Autowired CachingProvider cachingProvider; diff --git a/spring-context-support/src/test/java/org/springframework/cache/jcache/config/JCacheJavaConfigTests.java b/spring-context-support/src/test/java/org/springframework/cache/jcache/config/JCacheJavaConfigTests.java index 5c12aceac02..1dcc12540d1 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/jcache/config/JCacheJavaConfigTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/jcache/config/JCacheJavaConfigTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -180,7 +180,7 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests { @Configuration @EnableCaching - public static class EmptyConfigSupportConfig extends JCacheConfigurerSupport { + public static class EmptyConfigSupportConfig implements JCacheConfigurer { @Bean public CacheManager cm() { return new NoOpCacheManager(); @@ -190,7 +190,7 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests { @Configuration @EnableCaching - static class FullCachingConfigSupport extends JCacheConfigurerSupport { + static class FullCachingConfigSupport implements JCacheConfigurer { @Override @Bean @@ -220,7 +220,7 @@ public class JCacheJavaConfigTests extends AbstractJCacheAnnotationTests { @Configuration @EnableCaching - static class NoExceptionCacheResolverConfig extends JCacheConfigurerSupport { + static class NoExceptionCacheResolverConfig implements JCacheConfigurer { @Override @Bean diff --git a/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheErrorHandlerTests.java b/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheErrorHandlerTests.java index 3b341a0c4df..561c0af54d1 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheErrorHandlerTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheErrorHandlerTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.interceptor.CacheErrorHandler; import org.springframework.cache.interceptor.SimpleKeyGenerator; -import org.springframework.cache.jcache.config.JCacheConfigurerSupport; +import org.springframework.cache.jcache.config.JCacheConfigurer; import org.springframework.cache.support.SimpleCacheManager; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; @@ -141,7 +141,7 @@ public class JCacheErrorHandlerTests { @Configuration @EnableCaching - static class Config extends JCacheConfigurerSupport { + static class Config implements JCacheConfigurer { @Bean @Override diff --git a/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheKeyGeneratorTests.java b/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheKeyGeneratorTests.java index dd5497764b0..35db912df97 100644 --- a/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheKeyGeneratorTests.java +++ b/spring-context-support/src/test/java/org/springframework/cache/jcache/interceptor/JCacheKeyGeneratorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -34,7 +34,7 @@ import org.springframework.cache.concurrent.ConcurrentMapCacheManager; import org.springframework.cache.interceptor.KeyGenerator; import org.springframework.cache.interceptor.SimpleKey; import org.springframework.cache.interceptor.SimpleKeyGenerator; -import org.springframework.cache.jcache.config.JCacheConfigurerSupport; +import org.springframework.cache.jcache.config.JCacheConfigurer; import org.springframework.context.annotation.AnnotationConfigApplicationContext; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -97,7 +97,7 @@ public class JCacheKeyGeneratorTests { @Configuration @EnableCaching - static class Config extends JCacheConfigurerSupport { + static class Config implements JCacheConfigurer { @Bean @Override @@ -151,7 +151,7 @@ public class JCacheKeyGeneratorTests { @Override public Object generate(Object target, Method method, Object... params) { assertThat(Arrays.equals(expectedParams, params)).as("Unexpected parameters: expected: " - + Arrays.toString(this.expectedParams) + " but got: " + Arrays.toString(params)).isTrue(); + + Arrays.toString(this.expectedParams) + " but got: " + Arrays.toString(params)).isTrue(); return new SimpleKey(params); } } diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java index b7a609e9c23..e3dbe023f18 100644 --- a/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java +++ b/spring-context/src/main/java/org/springframework/cache/annotation/CachingConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2018 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,8 +26,7 @@ import org.springframework.lang.Nullable; * Interface to be implemented by @{@link org.springframework.context.annotation.Configuration * Configuration} classes annotated with @{@link EnableCaching} that wish or need to * specify explicitly how caches are resolved and how keys are generated for annotation-driven - * cache management. Consider extending {@link CachingConfigurerSupport}, which provides a - * stub implementation of all interface methods. + * cache management. * *

See @{@link EnableCaching} for general examples and context; see * {@link #cacheManager()}, {@link #cacheResolver()} and {@link #keyGenerator()} @@ -37,7 +36,6 @@ import org.springframework.lang.Nullable; * @author Stephane Nicoll * @since 3.1 * @see EnableCaching - * @see CachingConfigurerSupport */ public interface CachingConfigurer { @@ -64,7 +62,9 @@ public interface CachingConfigurer { * See @{@link EnableCaching} for more complete examples. */ @Nullable - CacheManager cacheManager(); + default CacheManager cacheManager() { + return null; + } /** * Return the {@link CacheResolver} bean to use to resolve regular caches for @@ -89,7 +89,9 @@ public interface CachingConfigurer { * See {@link EnableCaching} for more complete examples. */ @Nullable - CacheResolver cacheResolver(); + default CacheResolver cacheResolver() { + return null; + } /** * Return the key generator bean to use for annotation-driven cache management. @@ -110,7 +112,9 @@ public interface CachingConfigurer { * See @{@link EnableCaching} for more complete examples. */ @Nullable - KeyGenerator keyGenerator(); + default KeyGenerator keyGenerator() { + return null; + } /** * Return the {@link CacheErrorHandler} to use to handle cache-related errors. @@ -133,6 +137,8 @@ public interface CachingConfigurer { * See @{@link EnableCaching} for more complete examples. */ @Nullable - CacheErrorHandler errorHandler(); + default CacheErrorHandler errorHandler() { + return null; + } } diff --git a/spring-context/src/test/java/org/springframework/cache/CacheReproTests.java b/spring-context/src/test/java/org/springframework/cache/CacheReproTests.java index 4c81623f507..b08c6f895a0 100644 --- a/spring-context/src/test/java/org/springframework/cache/CacheReproTests.java +++ b/spring-context/src/test/java/org/springframework/cache/CacheReproTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2020 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import org.springframework.beans.testfixture.beans.TestBean; import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Caching; -import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.CachingConfigurer; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.concurrent.ConcurrentMapCache; import org.springframework.cache.concurrent.ConcurrentMapCacheManager; @@ -306,7 +306,7 @@ public class CacheReproTests { @Configuration @EnableCaching - public static class Spr13081Config extends CachingConfigurerSupport { + public static class Spr13081Config implements CachingConfigurer { @Bean @Override 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 858d9c0d5b9..6e10f5d04c6 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.Cacheable; -import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.CachingConfigurer; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -124,7 +124,7 @@ public class EnableCachingIntegrationTests { @Configuration - static class SharedConfig extends CachingConfigurerSupport { + static class SharedConfig implements CachingConfigurer { @Override @Bean diff --git a/spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java b/spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java index ea771747896..8c41ef04570 100644 --- a/spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java +++ b/spring-context/src/test/java/org/springframework/cache/config/EnableCachingTests.java @@ -22,7 +22,7 @@ import org.springframework.beans.factory.BeanCreationException; import org.springframework.beans.factory.NoSuchBeanDefinitionException; import org.springframework.beans.factory.NoUniqueBeanDefinitionException; import org.springframework.cache.CacheManager; -import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.CachingConfigurer; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.interceptor.CacheErrorHandler; import org.springframework.cache.interceptor.CacheInterceptor; @@ -150,7 +150,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests { @Configuration @EnableCaching - static class EnableCachingConfig extends CachingConfigurerSupport { + static class EnableCachingConfig implements CachingConfigurer { @Override @Bean @@ -227,7 +227,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests { @Configuration @EnableCaching - static class MultiCacheManagerConfigurer extends CachingConfigurerSupport { + static class MultiCacheManagerConfigurer implements CachingConfigurer { @Bean public CacheManager cm1() { @@ -253,7 +253,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests { @Configuration @EnableCaching - static class EmptyConfigSupportConfig extends CachingConfigurerSupport { + static class EmptyConfigSupportConfig implements CachingConfigurer { @Bean public CacheManager cm() { @@ -264,7 +264,7 @@ public class EnableCachingTests extends AbstractCacheAnnotationTests { @Configuration @EnableCaching - static class FullCachingConfig extends CachingConfigurerSupport { + static class FullCachingConfig implements CachingConfigurer { @Override @Bean diff --git a/spring-context/src/test/java/org/springframework/cache/config/ExpressionCachingIntegrationTests.java b/spring-context/src/test/java/org/springframework/cache/config/ExpressionCachingIntegrationTests.java index ae109aec5c5..5ba071381fc 100644 --- a/spring-context/src/test/java/org/springframework/cache/config/ExpressionCachingIntegrationTests.java +++ b/spring-context/src/test/java/org/springframework/cache/config/ExpressionCachingIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2016 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -20,7 +20,7 @@ import org.junit.jupiter.api.Test; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CachePut; -import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.CachingConfigurer; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.concurrent.ConcurrentMapCacheManager; import org.springframework.context.ConfigurableApplicationContext; @@ -122,7 +122,7 @@ public class ExpressionCachingIntegrationTests { @Configuration @EnableCaching - static class SharedConfig extends CachingConfigurerSupport { + static class SharedConfig implements CachingConfigurer { @Override @Bean 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 cfcd9cd713a..90e26dd51f3 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,7 +28,7 @@ import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.Cacheable; -import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.CachingConfigurer; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.support.SimpleCacheManager; import org.springframework.cache.support.SimpleValueWrapper; @@ -170,7 +170,7 @@ public class CacheErrorHandlerTests { @Configuration @EnableCaching - static class Config extends CachingConfigurerSupport { + static class Config implements CachingConfigurer { @Bean @Override 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 d17630a8ed2..c257534c6fb 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -27,7 +27,7 @@ import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.CachePut; import org.springframework.cache.annotation.Cacheable; -import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.CachingConfigurer; import org.springframework.cache.annotation.EnableCaching; import org.springframework.cache.concurrent.ConcurrentMapCacheManager; import org.springframework.context.ConfigurableApplicationContext; @@ -106,7 +106,7 @@ public class CachePutEvaluationTests { @Configuration @EnableCaching - static class Config extends CachingConfigurerSupport { + static class Config implements CachingConfigurer { @Bean @Override 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 ca2e76fc36f..86f0223402f 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 @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -29,7 +29,7 @@ import org.springframework.cache.Cache; import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CacheConfig; import org.springframework.cache.annotation.Cacheable; -import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.CachingConfigurer; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.ApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -149,7 +149,7 @@ public class CacheResolverCustomizationTests { @Configuration @EnableCaching - static class Config extends CachingConfigurerSupport { + static class Config implements CachingConfigurer { @Override @Bean diff --git a/spring-context/src/test/java/org/springframework/cache/interceptor/CacheSyncFailureTests.java b/spring-context/src/test/java/org/springframework/cache/interceptor/CacheSyncFailureTests.java index 2a3eccc6db7..de4776adae2 100644 --- a/spring-context/src/test/java/org/springframework/cache/interceptor/CacheSyncFailureTests.java +++ b/spring-context/src/test/java/org/springframework/cache/interceptor/CacheSyncFailureTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -26,7 +26,7 @@ import org.springframework.cache.CacheManager; import org.springframework.cache.annotation.CacheEvict; import org.springframework.cache.annotation.Cacheable; import org.springframework.cache.annotation.Caching; -import org.springframework.cache.annotation.CachingConfigurerSupport; +import org.springframework.cache.annotation.CachingConfigurer; import org.springframework.cache.annotation.EnableCaching; import org.springframework.context.ConfigurableApplicationContext; import org.springframework.context.annotation.AnnotationConfigApplicationContext; @@ -133,7 +133,7 @@ public class CacheSyncFailureTests { @Configuration @EnableCaching - static class Config extends CachingConfigurerSupport { + static class Config implements CachingConfigurer { @Override @Bean From b06d267232f3951e4d4bdbfbb04c4ce1d83f3b8c Mon Sep 17 00:00:00 2001 From: Stephane Nicoll Date: Tue, 14 Dec 2021 13:56:28 +0100 Subject: [PATCH 2/2] Remove references to AsyncConfigurerSupport Closes gh-27812 --- .../scheduling/annotation/AsyncConfigurer.java | 8 +------- .../AsyncAnnotationBeanPostProcessorTests.java | 8 ++++---- ...gTestExecutionListenerIntegrationTests.java | 18 +++++++++++------- 3 files changed, 16 insertions(+), 18 deletions(-) diff --git a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurer.java b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurer.java index eab9744cf34..488297171ba 100644 --- a/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurer.java +++ b/spring-context/src/main/java/org/springframework/scheduling/annotation/AsyncConfigurer.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2017 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -28,11 +28,6 @@ import org.springframework.lang.Nullable; * {@link AsyncUncaughtExceptionHandler} instance used to process exception thrown from * async method with {@code void} return type. * - *

Consider using {@link AsyncConfigurerSupport} providing default implementations for - * both methods if only one element needs to be customized. Furthermore, backward compatibility - * of this interface will be insured in case new customization options are introduced - * in the future. - * *

See @{@link EnableAsync} for usage examples. * * @author Chris Beams @@ -40,7 +35,6 @@ import org.springframework.lang.Nullable; * @since 3.1 * @see AbstractAsyncConfiguration * @see EnableAsync - * @see AsyncConfigurerSupport */ public interface AsyncConfigurer { diff --git a/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessorTests.java b/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessorTests.java index 477a97dec3d..2599d1a3cef 100644 --- a/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessorTests.java +++ b/spring-context/src/test/java/org/springframework/scheduling/annotation/AsyncAnnotationBeanPostProcessorTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -218,8 +218,8 @@ public class AsyncAnnotationBeanPostProcessorTests { private void assertFutureWithException(Future result, TestableAsyncUncaughtExceptionHandler exceptionHandler) { assertThatExceptionOfType(ExecutionException.class).isThrownBy( - result::get) - .withCauseExactlyInstanceOf(UnsupportedOperationException.class); + result::get) + .withCauseExactlyInstanceOf(UnsupportedOperationException.class); assertThat(exceptionHandler.isCalled()).as("handler should never be called with Future return type").isFalse(); } @@ -343,7 +343,7 @@ public class AsyncAnnotationBeanPostProcessorTests { @Configuration @EnableAsync - static class ConfigWithExceptionHandler extends AsyncConfigurerSupport { + static class ConfigWithExceptionHandler implements AsyncConfigurer { @Bean public ITestBean target() { diff --git a/spring-test/src/test/java/org/springframework/test/context/event/EventPublishingTestExecutionListenerIntegrationTests.java b/spring-test/src/test/java/org/springframework/test/context/event/EventPublishingTestExecutionListenerIntegrationTests.java index c3edfeb8386..7cba9a36350 100644 --- a/spring-test/src/test/java/org/springframework/test/context/event/EventPublishingTestExecutionListenerIntegrationTests.java +++ b/spring-test/src/test/java/org/springframework/test/context/event/EventPublishingTestExecutionListenerIntegrationTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2019 the original author or authors. + * Copyright 2002-2021 the original author or authors. * * Licensed under the Apache License, Version 2.0 (the "License"); * you may not use this file except in compliance with the License. @@ -31,7 +31,7 @@ import org.springframework.aop.interceptor.AsyncUncaughtExceptionHandler; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.scheduling.annotation.Async; -import org.springframework.scheduling.annotation.AsyncConfigurerSupport; +import org.springframework.scheduling.annotation.AsyncConfigurer; import org.springframework.scheduling.annotation.EnableAsync; import org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor; import org.springframework.stereotype.Component; @@ -73,13 +73,17 @@ public class EventPublishingTestExecutionListenerIntegrationTests { private static final CountDownLatch countDownLatch = new CountDownLatch(1); private final TestContextManager testContextManager = new TestContextManager(ExampleTestCase.class); + private final TestContext testContext = testContextManager.getTestContext(); + // Note that the following invocation of getApplicationContext() forces eager // loading of the test's ApplicationContext which consequently results in the // publication of all test execution events. Otherwise, TestContext#publishEvent // would never fire any events for ExampleTestCase. private final TestExecutionListener listener = testContext.getApplicationContext().getBean(TestExecutionListener.class); + private final Object testInstance = new ExampleTestCase(); + private final Method traceableTestMethod = ReflectionUtils.findMethod(ExampleTestCase.class, "traceableTest"); @@ -127,8 +131,8 @@ public class EventPublishingTestExecutionListenerIntegrationTests { public void beforeTestMethodAnnotationWithFailingEventListener() throws Exception { Method method = ReflectionUtils.findMethod(ExampleTestCase.class, "testWithFailingEventListener"); assertThatExceptionOfType(RuntimeException.class).isThrownBy(() -> - testContextManager.beforeTestMethod(testInstance, method)) - .withMessageContaining("Boom!"); + testContextManager.beforeTestMethod(testInstance, method)) + .withMessageContaining("Boom!"); verify(listener, only()).beforeTestMethod(testContext); } @@ -149,7 +153,7 @@ public class EventPublishingTestExecutionListenerIntegrationTests { verify(listener, only()).beforeTestMethod(testContext); assertThat(TrackingAsyncUncaughtExceptionHandler.asyncException.getMessage()) - .startsWith("Asynchronous exception for test method [" + methodName + "] in thread [" + THREAD_NAME_PREFIX); + .startsWith("Asynchronous exception for test method [" + methodName + "] in thread [" + THREAD_NAME_PREFIX); } @Test @@ -211,7 +215,7 @@ public class EventPublishingTestExecutionListenerIntegrationTests { @Configuration @EnableAsync(proxyTargetClass = true) - static class TestEventListenerConfiguration extends AsyncConfigurerSupport { + static class TestEventListenerConfiguration implements AsyncConfigurer { @Override public Executor getAsyncExecutor() { @@ -306,7 +310,7 @@ public class EventPublishingTestExecutionListenerIntegrationTests { public void beforeTestMethodWithAsyncFailure(BeforeTestMethodEvent event) throws Exception { this.listener.beforeTestMethod(event.getSource()); throw new RuntimeException(String.format("Asynchronous exception for test method [%s] in thread [%s]", - event.getTestContext().getTestMethod().getName(), Thread.currentThread().getName())); + event.getTestContext().getTestMethod().getName(), Thread.currentThread().getName())); } }