diff --git a/framework-docs/src/main/java/org/springframework/docs/integration/cache/cacheannotationenable/CacheConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/integration/cache/cacheannotationenable/CacheConfiguration.java index 53411fa7138..3c86a477e95 100644 --- a/framework-docs/src/main/java/org/springframework/docs/integration/cache/cacheannotationenable/CacheConfiguration.java +++ b/framework-docs/src/main/java/org/springframework/docs/integration/cache/cacheannotationenable/CacheConfiguration.java @@ -25,7 +25,7 @@ import org.springframework.context.annotation.Configuration; // tag::snippet[] @Configuration @EnableCaching -public class CacheConfiguration { +class CacheConfiguration { @Bean CacheManager cacheManager() { diff --git a/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationcaffeine/CacheConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationcaffeine/CacheConfiguration.java index 6618ee3353e..d2548ef6d77 100644 --- a/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationcaffeine/CacheConfiguration.java +++ b/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationcaffeine/CacheConfiguration.java @@ -22,7 +22,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration -public class CacheConfiguration { +class CacheConfiguration { // tag::snippet[] @Bean diff --git a/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationcaffeine/CustomCacheConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationcaffeine/CustomCacheConfiguration.java index db87fcc981c..a5c27321cfb 100644 --- a/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationcaffeine/CustomCacheConfiguration.java +++ b/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationcaffeine/CustomCacheConfiguration.java @@ -24,7 +24,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration -public class CustomCacheConfiguration { +class CustomCacheConfiguration { // tag::snippet[] @Bean diff --git a/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationjdk/CacheConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationjdk/CacheConfiguration.java index c8fae52e56b..87aec966c0f 100644 --- a/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationjdk/CacheConfiguration.java +++ b/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationjdk/CacheConfiguration.java @@ -26,7 +26,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration -public class CacheConfiguration { +class CacheConfiguration { // tag::snippet[] @Bean diff --git a/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationjsr107/CacheConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationjsr107/CacheConfiguration.java index 1c83d6c446e..874614ef7b9 100644 --- a/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationjsr107/CacheConfiguration.java +++ b/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationjsr107/CacheConfiguration.java @@ -24,7 +24,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration -public class CacheConfiguration { +class CacheConfiguration { // tag::snippet[] @Bean diff --git a/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationnoop/CacheConfiguration.java b/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationnoop/CacheConfiguration.java index 6944e7b785f..afb57bada1d 100644 --- a/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationnoop/CacheConfiguration.java +++ b/framework-docs/src/main/java/org/springframework/docs/integration/cache/cachestoreconfigurationnoop/CacheConfiguration.java @@ -24,7 +24,7 @@ import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @Configuration -public class CacheConfiguration { +class CacheConfiguration { private CacheManager jdkCache() { return null; 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 fe26f7d56d9..85c372dfeb3 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-2023 the original author or authors. + * Copyright 2002-2024 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,8 +29,8 @@ import org.springframework.lang.Nullable; * cache management. * *
See @{@link EnableCaching} for general examples and context; see - * {@link #cacheManager()}, {@link #cacheResolver()} and {@link #keyGenerator()} - * for detailed instructions. + * {@link #cacheManager()}, {@link #cacheResolver()}, {@link #keyGenerator()}, and + * {@link #errorHandler()} for detailed instructions. * * @author Chris Beams * @author Stephane Nicoll @@ -46,14 +46,15 @@ public interface CachingConfigurer { * management of the cache resolution, consider setting the * {@link CacheResolver} directly. *
Implementations must explicitly declare - * {@link org.springframework.context.annotation.Bean @Bean}, e.g. + * {@link org.springframework.context.annotation.Bean @Bean} so that + * the cache manager participates in the lifecycle of the context, e.g. *
* @Configuration
* @EnableCaching
- * public class AppConfig implements CachingConfigurer {
+ * class AppConfig implements CachingConfigurer {
* @Bean // important!
* @Override
- * public CacheManager cacheManager() {
+ * CacheManager cacheManager() {
* // configure and return CacheManager instance
* }
* // ...
@@ -70,17 +71,18 @@ public interface CachingConfigurer {
* Return the {@link CacheResolver} bean to use to resolve regular caches for
* annotation-driven cache management. This is an alternative and more powerful
* option of specifying the {@link CacheManager} to use.
- * If both a {@link #cacheManager()} and {@code #cacheResolver()} are set,
+ *
If both a {@link #cacheManager()} and {@code cacheResolver()} are set,
* the cache manager is ignored.
*
Implementations must explicitly declare
- * {@link org.springframework.context.annotation.Bean @Bean}, e.g.
+ * {@link org.springframework.context.annotation.Bean @Bean} so that
+ * the cache resolver participates in the lifecycle of the context, e.g.
*
* @Configuration
* @EnableCaching
- * public class AppConfig implements CachingConfigurer {
+ * class AppConfig implements CachingConfigurer {
* @Bean // important!
* @Override
- * public CacheResolver cacheResolver() {
+ * CacheResolver cacheResolver() {
* // configure and return CacheResolver instance
* }
* // ...
@@ -95,20 +97,8 @@ public interface CachingConfigurer {
/**
* Return the key generator bean to use for annotation-driven cache management.
- * Implementations must explicitly declare
- * {@link org.springframework.context.annotation.Bean @Bean}, e.g.
- *
- * @Configuration
- * @EnableCaching
- * public class AppConfig implements CachingConfigurer {
- * @Bean // important!
- * @Override
- * public KeyGenerator keyGenerator() {
- * // configure and return KeyGenerator instance
- * }
- * // ...
- * }
- *
+ * By default, {@link org.springframework.cache.interceptor.SimpleKeyGenerator}
+ * is used.
* See @{@link EnableCaching} for more complete examples.
*/
@Nullable
@@ -118,22 +108,8 @@ public interface CachingConfigurer {
/**
* Return the {@link CacheErrorHandler} to use to handle cache-related errors.
- *
By default,{@link org.springframework.cache.interceptor.SimpleCacheErrorHandler}
- * is used and simply throws the exception back at the client.
- *
Implementations must explicitly declare
- * {@link org.springframework.context.annotation.Bean @Bean}, e.g.
- *
- * @Configuration
- * @EnableCaching
- * public class AppConfig implements CachingConfigurer {
- * @Bean // important!
- * @Override
- * public CacheErrorHandler errorHandler() {
- * // configure and return CacheErrorHandler instance
- * }
- * // ...
- * }
- *
+ * By default, {@link org.springframework.cache.interceptor.SimpleCacheErrorHandler}
+ * is used, which throws the exception back at the client.
* See @{@link EnableCaching} for more complete examples.
*/
@Nullable
diff --git a/spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java b/spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java
index 06ea231402d..75ad63f8274 100644
--- a/spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java
+++ b/spring-context/src/main/java/org/springframework/cache/annotation/EnableCaching.java
@@ -1,5 +1,5 @@
/*
- * Copyright 2002-2023 the original author or authors.
+ * Copyright 2002-2024 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.
@@ -35,16 +35,16 @@ import org.springframework.core.Ordered;
*
* @Configuration
* @EnableCaching
- * public class AppConfig {
+ * class AppConfig {
*
* @Bean
- * public MyService myService() {
+ * MyService myService() {
* // configure and return a class having @Cacheable methods
* return new MyService();
* }
*
* @Bean
- * public CacheManager cacheManager() {
+ * CacheManager cacheManager() {
* // configure and return an implementation of Spring's CacheManager SPI
* SimpleCacheManager cacheManager = new SimpleCacheManager();
* cacheManager.setCaches(Set.of(new ConcurrentMapCache("default")));
@@ -103,26 +103,25 @@ import org.springframework.core.Ordered;
*
* @Configuration
* @EnableCaching
- * public class AppConfig implements CachingConfigurer {
+ * class AppConfig implements CachingConfigurer {
*
* @Bean
- * public MyService myService() {
+ * MyService myService() {
* // configure and return a class having @Cacheable methods
* return new MyService();
* }
*
* @Bean
* @Override
- * public CacheManager cacheManager() {
+ * CacheManager cacheManager() {
* // configure and return an implementation of Spring's CacheManager SPI
* SimpleCacheManager cacheManager = new SimpleCacheManager();
* cacheManager.setCaches(Set.of(new ConcurrentMapCache("default")));
* return cacheManager;
* }
*
- * @Bean
* @Override
- * public KeyGenerator keyGenerator() {
+ * KeyGenerator keyGenerator() {
* // configure and return an implementation of Spring's KeyGenerator SPI
* return new MyKeyGenerator();
* }
@@ -137,9 +136,8 @@ import org.springframework.core.Ordered;
* org.springframework.cache.interceptor.KeyGenerator KeyGenerator} SPI. Normally,
* {@code @EnableCaching} will configure Spring's
* {@link org.springframework.cache.interceptor.SimpleKeyGenerator SimpleKeyGenerator}
- * for this purpose, but when implementing {@code CachingConfigurer}, a key generator
- * must be provided explicitly. Return {@code null} or {@code new SimpleKeyGenerator()}
- * from this method if no customization is necessary.
+ * for this purpose, but when implementing {@code CachingConfigurer}, a custom key
+ * generator can be specified.
*
* {@link CachingConfigurer} offers additional customization options:
* see the {@link CachingConfigurer} javadoc for further details.