From 75912a06c5613a2ea1305ad4d8ad6bc4be7765ce Mon Sep 17 00:00:00 2001 From: Stephane Nicoll <snicoll@pivotal.io> Date: Fri, 17 Feb 2017 12:30:57 +0100 Subject: [PATCH] Polish contribution Closes gh-229 --- pom.xml | 2 +- .../samples/petclinic/system/CacheConfig.java | 20 ++++++++++--------- 2 files changed, 12 insertions(+), 10 deletions(-) diff --git a/pom.xml b/pom.xml index 82e78e1..d879eb9 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 4bc23bb..13e194c 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); } } -- GitLab