Skip to content

Commit d189dbf

Browse files
authored
Merge pull request #182 from snicoll/ehcache3
Upgrade to Ehcache 3 and Java config
2 parents b96e109 + a41b83a commit d189dbf

File tree

4 files changed

+35
-459
lines changed

4 files changed

+35
-459
lines changed

pom.xml

Lines changed: 5 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -60,10 +60,6 @@
6060
<groupId>org.springframework.boot</groupId>
6161
<artifactId>spring-boot-starter-web</artifactId>
6262
</dependency>
63-
<dependency>
64-
<groupId>org.springframework</groupId>
65-
<artifactId>spring-context-support</artifactId>
66-
</dependency>
6763

6864
<dependency>
6965
<groupId>org.apache.tomcat.embed</groupId>
@@ -75,18 +71,6 @@
7571
<artifactId>jstl</artifactId>
7672
</dependency>
7773

78-
79-
<!-- used for EhCacheCacheManager -->
80-
<dependency>
81-
<groupId>org.aspectj</groupId>
82-
<artifactId>aspectjrt</artifactId>
83-
</dependency>
84-
<dependency>
85-
<groupId>org.aspectj</groupId>
86-
<artifactId>aspectjweaver</artifactId>
87-
<scope>runtime</scope>
88-
</dependency>
89-
9074
<!-- Date and Time -->
9175
<dependency>
9276
<groupId>joda-time</groupId>
@@ -124,14 +108,12 @@
124108

125109
<!-- EhCache -->
126110
<dependency>
127-
<groupId>net.sf.ehcache</groupId>
111+
<groupId>javax.cache</groupId>
112+
<artifactId>cache-api</artifactId>
113+
</dependency>
114+
<dependency>
115+
<groupId>org.ehcache</groupId>
128116
<artifactId>ehcache</artifactId>
129-
<exclusions>
130-
<exclusion>
131-
<groupId>commons-logging</groupId>
132-
<artifactId>commons-logging</artifactId>
133-
</exclusion>
134-
</exclusions>
135117
</dependency>
136118

137119
<!-- Dandelion -->

src/main/java/org/springframework/samples/petclinic/config/CacheConfig.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,19 @@
11
package org.springframework.samples.petclinic.config;
22

3+
import java.util.concurrent.TimeUnit;
4+
import javax.cache.CacheManager;
5+
6+
import org.ehcache.config.CacheConfiguration;
7+
import org.ehcache.config.builders.CacheConfigurationBuilder;
8+
import org.ehcache.config.builders.ResourcePoolsBuilder;
9+
import org.ehcache.config.units.EntryUnit;
10+
import org.ehcache.expiry.Duration;
11+
import org.ehcache.expiry.Expirations;
12+
import org.ehcache.jsr107.Eh107Configuration;
13+
14+
import org.springframework.boot.autoconfigure.cache.JCacheManagerCustomizer;
315
import org.springframework.cache.annotation.EnableCaching;
16+
import org.springframework.context.annotation.Bean;
417
import org.springframework.context.annotation.Configuration;
518
import org.springframework.context.annotation.Profile;
619

@@ -11,4 +24,21 @@
1124
@EnableCaching
1225
@Profile("production")
1326
public class CacheConfig {
27+
28+
@Bean
29+
public JCacheManagerCustomizer cacheManagerCustomizer() {
30+
return new JCacheManagerCustomizer() {
31+
@Override
32+
public void customize(CacheManager cacheManager) {
33+
CacheConfiguration<Object, Object> config = CacheConfigurationBuilder
34+
.newCacheConfigurationBuilder(Object.class, Object.class,
35+
ResourcePoolsBuilder.newResourcePoolsBuilder()
36+
.heap(100, EntryUnit.ENTRIES))
37+
.withExpiry(Expirations.timeToLiveExpiration(Duration.of(60, TimeUnit.SECONDS)))
38+
.build();
39+
cacheManager.createCache("vets", Eh107Configuration.fromEhcacheCacheConfiguration(config));
40+
}
41+
};
42+
}
43+
1444
}

src/main/resources/ehcache.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)