Skip to content

Commit 748b4dd

Browse files
committed
[DRAFT] Restore Ehcache 3 Support
1 parent bfe9ded commit 748b4dd

File tree

7 files changed

+97
-4
lines changed

7 files changed

+97
-4
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/resources/ehcache3.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,8 @@
33
xmlns='http://www.ehcache.org/v3'
44
xmlns:jsr107='http://www.ehcache.org/v3/jsr107'
55
xsi:schemaLocation="
6-
http://www.ehcache.org/v3 https://www.ehcache.org/schema/ehcache-core-3.1.xsd
7-
http://www.ehcache.org/v3/jsr107 https://www.ehcache.org/schema/ehcache-107-ext-3.1.xsd">
6+
http://www.ehcache.org/v3 https://www.ehcache.org/schema/ehcache-core-3.10.xsd
7+
http://www.ehcache.org/v3/jsr107 https://www.ehcache.org/schema/ehcache-107-ext-3.10.xsd">
88

99
<cache-template name="example">
1010
<heap unit="entries">200</heap>

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

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -191,6 +191,19 @@ bom {
191191
]
192192
}
193193
}
194+
library("Ehcache3", "3.10.0") {
195+
group("org.ehcache") {
196+
modules = [
197+
"ehcache" {
198+
classifier = 'jakarta'
199+
},
200+
"ehcache-clustered",
201+
"ehcache-transactions" {
202+
classifier = 'jakarta'
203+
}
204+
]
205+
}
206+
}
194207
library("Elasticsearch", "7.17.0") {
195208
group("org.elasticsearch") {
196209
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 with 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)