diff --git a/pom.xml b/pom.xml index 82e78e181b18c9c14a27439864e2f20eec372d08..d879eb92951ed2e3f0c6fd4e51a849bfb7683ee0 100644 --- a/pom.xml +++ b/pom.xml @@ -79,7 +79,7 @@ <scope>runtime</scope> </dependency> - <!-- EhCache --> + <!-- caching --> <dependency> <groupId>javax.cache</groupId> <artifactId>cache-api</artifactId> diff --git a/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java b/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java index 4bc23bbe6dad115ce6af5dec0c9fdd036cc1a6d5..13e194c35245330af83f1dbc1ae10cd6f1a2f770 100755 --- a/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java +++ b/src/main/java/org/springframework/samples/petclinic/system/CacheConfig.java @@ -3,9 +3,9 @@ package org.springframework.samples.petclinic.system; import javax.cache.configuration.Configuration; import javax.cache.configuration.MutableConfiguration; -import org.springframework.boot.autoconfigure.cache.CacheManagerCustomizer; +import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer; import org.springframework.cache.annotation.EnableCaching; -import org.springframework.cache.jcache.JCacheCacheManager; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Profile; /** @@ -14,17 +14,19 @@ import org.springframework.context.annotation.Profile; @org.springframework.context.annotation.Configuration @EnableCaching @Profile("production") -class CacheConfig implements CacheManagerCustomizer<JCacheCacheManager> { +class CacheConfig { - @Override - public void customize(JCacheCacheManager cacheManager) { - Configuration<Object, Object> cacheConfiguration = createCacheConfiguration(); - cacheManager.getCacheManager().createCache("vets", cacheConfiguration); + @Bean + public JCacheManagerCustomizer cacheManagerCustomizer() { + return cm -> { + Configuration<Object, Object> cacheConfiguration = createCacheConfiguration(); + cm.createCache("vets", cacheConfiguration); + }; } private Configuration<Object, Object> createCacheConfiguration() { - // Create a cache using infinite heap. A real application will want to use an implementation dependent - // configuration that will better fit your needs + // Create a cache using infinite heap. A real application will want to use an + // implementation dependent configuration that will better fit your needs return new MutableConfiguration<>().setStatisticsEnabled(true); } }