Skip to content

Commit 3b37102

Browse files
committed
[DRAFT] Restore Ehcache 3 Support
1 parent 29e0275 commit 3b37102

File tree

7 files changed

+96
-6
lines changed

7 files changed

+96
-6
lines changed

spring-boot-project/spring-boot-autoconfigure/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,11 @@ dependencies {
8888
optional("org.eclipse.jetty.websocket:websocket-jetty-server") {
8989
exclude(group: "org.eclipse.jetty", module: "jetty-jndi")
9090
}
91+
optional("org.ehcache:ehcache") {
92+
artifact {
93+
classifier = 'jakarta'
94+
}
95+
}
9196
optional("org.elasticsearch.client:elasticsearch-rest-client") {
9297
exclude group: "commons-logging", module: "commons-logging"
9398
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2012-2019 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.cache;
18+
19+
import org.ehcache.jsr107.EhcacheCachingProvider;
20+
import org.junit.jupiter.api.Test;
21+
22+
import org.springframework.boot.autoconfigure.cache.CacheAutoConfigurationTests.DefaultCacheConfiguration;
23+
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
24+
import org.springframework.cache.jcache.JCacheCacheManager;
25+
import org.springframework.core.io.ClassPathResource;
26+
import org.springframework.core.io.Resource;
27+
28+
import static org.assertj.core.api.Assertions.assertThat;
29+
30+
/**
31+
* Tests for {@link CacheAutoConfiguration} with EhCache 3.
32+
*
33+
* @author Stephane Nicoll
34+
* @author Andy Wilkinson
35+
*/
36+
@ClassPathExclusions("ehcache-2*.jar")
37+
class EhCache3CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests {
38+
39+
@Test
40+
void ehcache3AsJCacheWithCaches() {
41+
String cachingProviderFqn = EhcacheCachingProvider.class.getName();
42+
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
43+
.withPropertyValues("spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn,
44+
"spring.cache.cacheNames[0]=foo", "spring.cache.cacheNames[1]=bar")
45+
.run((context) -> {
46+
JCacheCacheManager cacheManager = getCacheManager(context, JCacheCacheManager.class);
47+
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
48+
});
49+
}
50+
51+
@Test
52+
void ehcache3AsJCacheWithConfig() {
53+
String cachingProviderFqn = EhcacheCachingProvider.class.getName();
54+
String configLocation = "ehcache3.xml";
55+
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
56+
.withPropertyValues("spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn,
57+
"spring.cache.jcache.config=" + configLocation)
58+
.run((context) -> {
59+
JCacheCacheManager cacheManager = getCacheManager(context, JCacheCacheManager.class);
60+
61+
Resource configResource = new ClassPathResource(configLocation);
62+
assertThat(cacheManager.getCacheManager().getURI()).isEqualTo(configResource.getURI());
63+
assertThat(cacheManager.getCacheNames()).containsOnly("foo", "bar");
64+
});
65+
}
66+
67+
}

spring-boot-project/spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/orm/jpa/Hibernate2ndLevelCacheIntegrationTests.java

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616

1717
package org.springframework.boot.autoconfigure.orm.jpa;
1818

19-
import com.hazelcast.cache.impl.HazelcastServerCachingProvider;
19+
import org.ehcache.jsr107.EhcacheCachingProvider;
2020
import org.junit.jupiter.api.Test;
2121

2222
import org.springframework.boot.autoconfigure.AutoConfigurations;
@@ -41,9 +41,9 @@ class Hibernate2ndLevelCacheIntegrationTests {
4141
.withUserConfiguration(TestConfiguration.class);
4242

4343
@Test
44-
void hibernate2ndLevelCacheWithJCacheAndHazelcast() {
45-
String cachingProviderFqn = HazelcastServerCachingProvider.class.getName();
46-
String configLocation = "classpath:hazelcast.xml";
44+
void hibernate2ndLevelCacheWithJCacheAndEhCache3() {
45+
String cachingProviderFqn = EhcacheCachingProvider.class.getName();
46+
String configLocation = "ehcache3.xml";
4747
this.contextRunner
4848
.withPropertyValues("spring.cache.type=jcache", "spring.cache.jcache.provider=" + cachingProviderFqn,
4949
"spring.cache.jcache.config=" + configLocation,

spring-boot-project/spring-boot-dependencies/build.gradle

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,16 @@ bom {
191191
]
192192
}
193193
}
194+
library("Ehcache3", "3.10.0-alpha0") {
195+
group("org.ehcache") {
196+
modules = [
197+
"ehcache" {
198+
classifier = 'jakarta'
199+
},
200+
"ehcache-clustered"
201+
]
202+
}
203+
}
194204
library("Elasticsearch", "7.17.0") {
195205
group("org.elasticsearch") {
196206
modules = [

spring-boot-project/spring-boot-docs/src/docs/asciidoc/documentation/io.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22
== IO
33
If your application needs IO capabilities, see one or more of the following sections:
44

5-
* *Caching:* <<io#io.caching, Caching support with Hazelcast and more>>
5+
* *Caching:* <<io#io.caching, Caching support EhCache, Hazelcast and more>>
66
* *Quartz:* <<io#io.quartz, Quartz Scheduling>>
77
* *Mail:* <<io#io.email, Sending Email>>
88
* *Validation:* <<io#io.validation, JSR-303 Validation>>

spring-boot-project/spring-boot-docs/src/docs/asciidoc/io/caching.adoc

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,7 @@ The cache abstraction does not provide an actual store and relies on abstraction
3737
If you have not defined a bean of type `CacheManager` or a `CacheResolver` named `cacheResolver` (see {spring-framework-api}/cache/annotation/CachingConfigurer.html[`CachingConfigurer`]), Spring Boot tries to detect the following providers (in the indicated order):
3838

3939
. <<io#io.caching.provider.generic,Generic>>
40-
. <<io#io.caching.provider.jcache,JCache (JSR-107)>> (Hazelcast and others)
40+
. <<io#io.caching.provider.jcache,JCache (JSR-107)>> (EhCache 3, Hazelcast, and others)
4141
. <<io#io.caching.provider.hazelcast,Hazelcast>>
4242
. <<io#io.caching.provider.couchbase,Couchbase>>
4343
. <<io#io.caching.provider.redis,Redis>>

spring-boot-tests/spring-boot-smoke-tests/spring-boot-smoke-test-cache/build.gradle

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,14 @@ def caches = [
1212
"couchbase": [
1313
project(":spring-boot-project:spring-boot-starters:spring-boot-starter-data-couchbase")
1414
],
15+
"ehcache": [
16+
"javax.cache:cache-api",
17+
dependencies.create("org.ehcache:ehcache") {
18+
artifact {
19+
classifier = 'jakarta'
20+
}
21+
}
22+
],
1523
"hazelcast": [
1624
"com.hazelcast:hazelcast",
1725
"com.hazelcast:hazelcast-spring"

0 commit comments

Comments
 (0)