diff --git a/pom.xml b/pom.xml index 06741b463..fb363d313 100644 --- a/pom.xml +++ b/pom.xml @@ -59,10 +59,6 @@ org.springframework.boot spring-boot-starter-web - - org.springframework - spring-context-support - org.apache.tomcat.embed @@ -74,18 +70,6 @@ jstl - - - - org.aspectj - aspectjrt - - - org.aspectj - aspectjweaver - runtime - - joda-time @@ -123,14 +107,12 @@ - net.sf.ehcache + javax.cache + cache-api + + + org.ehcache ehcache - - - commons-logging - commons-logging - - diff --git a/src/main/java/org/springframework/samples/petclinic/config/CacheConfig.java b/src/main/java/org/springframework/samples/petclinic/config/CacheConfig.java index fc4a0bcc1..4e1a6a0b0 100644 --- a/src/main/java/org/springframework/samples/petclinic/config/CacheConfig.java +++ b/src/main/java/org/springframework/samples/petclinic/config/CacheConfig.java @@ -1,6 +1,19 @@ package org.springframework.samples.petclinic.config; +import java.util.concurrent.TimeUnit; +import javax.cache.CacheManager; + +import org.ehcache.config.CacheConfiguration; +import org.ehcache.config.builders.CacheConfigurationBuilder; +import org.ehcache.config.builders.ResourcePoolsBuilder; +import org.ehcache.config.units.EntryUnit; +import org.ehcache.expiry.Duration; +import org.ehcache.expiry.Expirations; +import org.ehcache.jsr107.Eh107Configuration; + +import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer; import org.springframework.cache.annotation.EnableCaching; +import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.context.annotation.Profile; @@ -11,4 +24,21 @@ import org.springframework.context.annotation.Profile; @EnableCaching @Profile("production") public class CacheConfig { + + @Bean + public JCacheManagerCustomizer cacheManagerCustomizer() { + return new JCacheManagerCustomizer() { + @Override + public void customize(CacheManager cacheManager) { + CacheConfiguration config = CacheConfigurationBuilder + .newCacheConfigurationBuilder(Object.class, Object.class, + ResourcePoolsBuilder.newResourcePoolsBuilder() + .heap(100, EntryUnit.ENTRIES)) + .withExpiry(Expirations.timeToLiveExpiration(Duration.of(60, TimeUnit.SECONDS))) + .build(); + cacheManager.createCache("vets", Eh107Configuration.fromEhcacheCacheConfiguration(config)); + } + }; + } + } diff --git a/src/main/resources/ehcache.xml b/src/main/resources/ehcache.xml deleted file mode 100644 index 32e509953..000000000 --- a/src/main/resources/ehcache.xml +++ /dev/null @@ -1,17 +0,0 @@ - - - - - - - diff --git a/src/main/resources/ehcache.xsd b/src/main/resources/ehcache.xsd deleted file mode 100644 index bfc19ddb1..000000000 --- a/src/main/resources/ehcache.xsd +++ /dev/null @@ -1,419 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - \ No newline at end of file