Remove support for EhCache 2

Closes gh-28588
pull/28862/head
Andy Wilkinson 3 years ago
parent ef02cc9bff
commit 64bf33038d

@ -80,7 +80,6 @@ dependencies {
optional("jakarta.persistence:jakarta.persistence-api")
optional("jakarta.servlet:jakarta.servlet-api")
optional("javax.cache:cache-api")
optional("net.sf.ehcache:ehcache")
optional("org.apache.activemq:activemq-broker") {
exclude group: "org.apache.geronimo.specs", module: "geronimo-jms_1.1_spec"
exclude group: "org.apache.geronimo.specs", module: "geronimo-j2ee-management_1.1_spec"

@ -19,17 +19,14 @@ package org.springframework.boot.actuate.autoconfigure.metrics.cache;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.spring.cache.HazelcastCache;
import io.micrometer.core.instrument.binder.MeterBinder;
import net.sf.ehcache.Ehcache;
import org.springframework.boot.actuate.metrics.cache.CacheMeterBinderProvider;
import org.springframework.boot.actuate.metrics.cache.CaffeineCacheMeterBinderProvider;
import org.springframework.boot.actuate.metrics.cache.EhCache2CacheMeterBinderProvider;
import org.springframework.boot.actuate.metrics.cache.HazelcastCacheMeterBinderProvider;
import org.springframework.boot.actuate.metrics.cache.JCacheCacheMeterBinderProvider;
import org.springframework.boot.actuate.metrics.cache.RedisCacheMeterBinderProvider;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.cache.caffeine.CaffeineCache;
import org.springframework.cache.ehcache.EhCacheCache;
import org.springframework.cache.jcache.JCacheCache;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -55,17 +52,6 @@ class CacheMeterBinderProvidersConfiguration {
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ EhCacheCache.class, Ehcache.class })
static class EhCache2CacheMeterBinderProviderConfiguration {
@Bean
EhCache2CacheMeterBinderProvider ehCache2CacheMeterBinderProvider() {
return new EhCache2CacheMeterBinderProvider();
}
}
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ HazelcastCache.class, Hazelcast.class })
static class HazelcastCacheMeterBinderProviderConfiguration {

@ -39,7 +39,6 @@ dependencies {
}
optional("javax.cache:cache-api")
optional("jakarta.jms:jakarta.jms-api")
optional("net.sf.ehcache:ehcache")
optional("org.apache.solr:solr-solrj") {
exclude group: "org.slf4j", module: "jcl-over-slf4j"
}

@ -1,38 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.metrics.cache;
import io.micrometer.core.instrument.Tag;
import io.micrometer.core.instrument.binder.MeterBinder;
import io.micrometer.core.instrument.binder.cache.EhCache2Metrics;
import org.springframework.cache.ehcache.EhCacheCache;
/**
* {@link CacheMeterBinderProvider} implementation for EhCache2.
*
* @author Stephane Nicoll
* @since 2.0.0
*/
public class EhCache2CacheMeterBinderProvider implements CacheMeterBinderProvider<EhCacheCache> {
@Override
public MeterBinder getMeterBinder(EhCacheCache cache, Iterable<Tag> tags) {
return new EhCache2Metrics(cache.getNativeCache(), tags);
}
}

@ -1,57 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.actuate.metrics.cache;
import java.util.Collections;
import io.micrometer.core.instrument.binder.MeterBinder;
import io.micrometer.core.instrument.binder.cache.EhCache2Metrics;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import net.sf.ehcache.config.CacheConfiguration;
import net.sf.ehcache.config.Configuration;
import org.junit.jupiter.api.Test;
import org.springframework.cache.ehcache.EhCacheCache;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link EhCache2CacheMeterBinderProvider}.
*
* @author Stephane Nicoll
*/
class EhCache2CacheMeterBinderProviderTests {
@Test
void ehCache2CacheProvider() {
CacheManager cacheManager = new CacheManager(
new Configuration().name("EhCacheCacheTests").defaultCache(new CacheConfiguration("default", 100)));
try {
Cache nativeCache = new Cache(new CacheConfiguration("test", 100));
cacheManager.addCache(nativeCache);
EhCacheCache cache = new EhCacheCache(nativeCache);
MeterBinder meterBinder = new EhCache2CacheMeterBinderProvider().getMeterBinder(cache,
Collections.emptyList());
assertThat(meterBinder).isInstanceOf(EhCache2Metrics.class);
}
finally {
cacheManager.shutdown();
}
}
}

@ -51,7 +51,6 @@ dependencies {
optional("jakarta.ws.rs:jakarta.ws.rs-api")
optional("javax.cache:cache-api")
optional("javax.money:money-api")
optional("net.sf.ehcache:ehcache")
optional("org.apache.activemq:activemq-broker") {
exclude group: "org.apache.geronimo.specs", module: "geronimo-j2ee-management_1.1_spec"
exclude group: "org.apache.geronimo.specs", module: "geronimo-jms_1.1_spec"

@ -36,7 +36,6 @@ final class CacheConfigurations {
static {
Map<CacheType, String> mappings = new EnumMap<>(CacheType.class);
mappings.put(CacheType.GENERIC, GenericCacheConfiguration.class.getName());
mappings.put(CacheType.EHCACHE, EhCacheCacheConfiguration.class.getName());
mappings.put(CacheType.HAZELCAST, HazelcastCacheConfiguration.class.getName());
mappings.put(CacheType.INFINISPAN, InfinispanCacheConfiguration.class.getName());
mappings.put(CacheType.JCACHE, JCacheCacheConfiguration.class.getName());

@ -50,8 +50,6 @@ public class CacheProperties {
private final Couchbase couchbase = new Couchbase();
private final EhCache ehcache = new EhCache();
private final Infinispan infinispan = new Infinispan();
private final JCache jcache = new JCache();
@ -82,10 +80,6 @@ public class CacheProperties {
return this.couchbase;
}
public EhCache getEhcache() {
return this.ehcache;
}
public Infinispan getInfinispan() {
return this.infinispan;
}
@ -156,26 +150,6 @@ public class CacheProperties {
}
/**
* EhCache specific cache properties.
*/
public static class EhCache {
/**
* The location of the configuration file to use to initialize EhCache.
*/
private Resource config;
public Resource getConfig() {
return this.config;
}
public void setConfig(Resource config) {
this.config = config;
}
}
/**
* Infinispan specific cache properties.
*/

@ -36,11 +36,6 @@ public enum CacheType {
*/
JCACHE,
/**
* EhCache backed caching.
*/
EHCACHE,
/**
* Hazelcast backed caching.
*/

@ -1,74 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.cache;
import net.sf.ehcache.Cache;
import net.sf.ehcache.CacheManager;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
import org.springframework.boot.autoconfigure.condition.ResourceCondition;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.ehcache.EhCacheManagerUtils;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Conditional;
import org.springframework.context.annotation.Configuration;
import org.springframework.core.io.Resource;
/**
* EhCache cache configuration. Only kick in if a configuration file location is set or if
* a default configuration file exists.
*
* @author Eddú Meléndez
* @author Stephane Nicoll
* @author Madhura Bhave
*/
@Configuration(proxyBeanMethods = false)
@ConditionalOnClass({ Cache.class, EhCacheCacheManager.class })
@ConditionalOnMissingBean(org.springframework.cache.CacheManager.class)
@Conditional({ CacheCondition.class, EhCacheCacheConfiguration.ConfigAvailableCondition.class })
class EhCacheCacheConfiguration {
@Bean
EhCacheCacheManager cacheManager(CacheManagerCustomizers customizers, CacheManager ehCacheCacheManager) {
return customizers.customize(new EhCacheCacheManager(ehCacheCacheManager));
}
@Bean
@ConditionalOnMissingBean
CacheManager ehCacheCacheManager(CacheProperties cacheProperties) {
Resource location = cacheProperties.resolveConfigLocation(cacheProperties.getEhcache().getConfig());
if (location != null) {
return EhCacheManagerUtils.buildCacheManager(location);
}
return EhCacheManagerUtils.buildCacheManager();
}
/**
* Determine if the EhCache configuration is available. This either kick in if a
* default configuration has been found or if property referring to the file to use
* has been set.
*/
static class ConfigAvailableCondition extends ResourceCondition {
ConfigAvailableCondition() {
super("EhCache", "spring.cache.ehcache.config", "classpath:/ehcache.xml");
}
}
}

@ -31,7 +31,6 @@ import org.springframework.boot.test.context.runner.ContextConsumer;
import org.springframework.cache.CacheManager;
import org.springframework.cache.caffeine.CaffeineCacheManager;
import org.springframework.cache.concurrent.ConcurrentMapCacheManager;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import org.springframework.cache.support.SimpleCacheManager;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
@ -114,13 +113,6 @@ abstract class AbstractCacheAutoConfigurationTests {
};
}
@Bean
CacheManagerCustomizer<EhCacheCacheManager> ehcacheCacheManagerCustomizer() {
return new CacheManagerTestCustomizer<EhCacheCacheManager>() {
};
}
@Bean
CacheManagerCustomizer<HazelcastCacheManager> hazelcastCacheManagerCustomizer() {
return new CacheManagerTestCustomizer<HazelcastCacheManager>() {

@ -32,7 +32,6 @@ import com.hazelcast.cache.impl.HazelcastServerCachingProvider;
import com.hazelcast.core.Hazelcast;
import com.hazelcast.core.HazelcastInstance;
import com.hazelcast.spring.cache.HazelcastCacheManager;
import net.sf.ehcache.Status;
import org.infinispan.configuration.cache.ConfigurationBuilder;
import org.infinispan.jcache.embedded.JCachingProvider;
import org.infinispan.spring.embedded.provider.SpringEmbeddedCacheManager;
@ -837,20 +836,6 @@ class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests {
}
@Configuration(proxyBeanMethods = false)
@EnableCaching
static class EhCacheCustomCacheManager {
@Bean
net.sf.ehcache.CacheManager customEhCacheCacheManager() {
net.sf.ehcache.CacheManager cacheManager = mock(net.sf.ehcache.CacheManager.class);
given(cacheManager.getStatus()).willReturn(Status.STATUS_ALIVE);
given(cacheManager.getCacheNames()).willReturn(new String[0]);
return cacheManager;
}
}
@Configuration(proxyBeanMethods = false)
@EnableCaching
static class HazelcastCustomHazelcastInstance {

@ -1,81 +0,0 @@
/*
* Copyright 2012-2019 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package org.springframework.boot.autoconfigure.cache;
import org.junit.jupiter.api.Test;
import org.springframework.boot.autoconfigure.AutoConfigurations;
import org.springframework.boot.autoconfigure.cache.CacheAutoConfigurationTests.DefaultCacheAndCustomizersConfiguration;
import org.springframework.boot.autoconfigure.cache.CacheAutoConfigurationTests.DefaultCacheConfiguration;
import org.springframework.boot.autoconfigure.cache.CacheAutoConfigurationTests.EhCacheCustomCacheManager;
import org.springframework.boot.test.context.runner.ApplicationContextRunner;
import org.springframework.boot.testsupport.classpath.ClassPathExclusions;
import org.springframework.cache.ehcache.EhCacheCacheManager;
import static org.assertj.core.api.Assertions.assertThat;
/**
* Tests for {@link CacheAutoConfiguration} with EhCache 2.
*
* @author Stephane Nicoll
* @author Andy Wilkinson
*/
@ClassPathExclusions("ehcache-3*.jar")
class EhCache2CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationTests {
private final ApplicationContextRunner contextRunner = new ApplicationContextRunner()
.withConfiguration(AutoConfigurations.of(CacheAutoConfiguration.class));
@Test
void ehCacheWithCaches() {
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
.withPropertyValues("spring.cache.type=ehcache").run((context) -> {
EhCacheCacheManager cacheManager = getCacheManager(context, EhCacheCacheManager.class);
assertThat(cacheManager.getCacheNames()).containsOnly("cacheTest1", "cacheTest2");
assertThat(context.getBean(net.sf.ehcache.CacheManager.class))
.isEqualTo(cacheManager.getCacheManager());
});
}
@Test
void ehCacheWithCustomizers() {
this.contextRunner.withUserConfiguration(DefaultCacheAndCustomizersConfiguration.class)
.withPropertyValues("spring.cache.type=ehcache")
.run(verifyCustomizers("allCacheManagerCustomizer", "ehcacheCacheManagerCustomizer"));
}
@Test
void ehCacheWithConfig() {
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
.withPropertyValues("spring.cache.type=ehcache",
"spring.cache.ehcache.config=cache/ehcache-override.xml")
.run((context) -> {
EhCacheCacheManager cacheManager = getCacheManager(context, EhCacheCacheManager.class);
assertThat(cacheManager.getCacheNames()).containsOnly("cacheOverrideTest1", "cacheOverrideTest2");
});
}
@Test
void ehCacheWithExistingCacheManager() {
this.contextRunner.withUserConfiguration(EhCacheCustomCacheManager.class)
.withPropertyValues("spring.cache.type=ehcache").run((context) -> {
EhCacheCacheManager cacheManager = getCacheManager(context, EhCacheCacheManager.class);
assertThat(cacheManager.getCacheManager()).isEqualTo(context.getBean("customEhCacheCacheManager"));
});
}
}

@ -257,13 +257,6 @@ bom {
]
}
}
library("Ehcache", "2.10.9.2") {
group("net.sf.ehcache") {
modules = [
"ehcache"
]
}
}
library("Ehcache3", "3.9.7") {
group("org.ehcache") {
modules = [

@ -860,7 +860,6 @@ Additional, cache-specific metrics are also available.
The following cache libraries are supported:
* Caffeine
* EhCache 2
* Hazelcast
* Any compliant JCache (JSR-107) implementation
* Redis

@ -277,7 +277,6 @@ boot-features-caching=features.caching
boot-features-caching-provider=features.caching.provider
boot-features-caching-provider-generic=features.caching.provider.generic
boot-features-caching-provider-jcache=features.caching.provider.jcache
boot-features-caching-provider-ehcache2=features.caching.provider.ehcache2
boot-features-caching-provider-hazelcast=features.caching.provider.hazelcast
boot-features-caching-provider-infinispan=features.caching.provider.infinispan
boot-features-caching-provider-couchbase=features.caching.provider.couchbase
@ -784,7 +783,6 @@ features.caching=io.caching
features.caching.provider=io.caching.provider
features.caching.provider.generic=io.caching.provider.generic
features.caching.provider.jcache=io.caching.provider.jcache
features.caching.provider.ehcache2=io.caching.provider.ehcache2
features.caching.provider.hazelcast=io.caching.provider.hazelcast
features.caching.provider.infinispan=io.caching.provider.infinispan
features.caching.provider.couchbase=io.caching.provider.couchbase

@ -41,7 +41,6 @@ If you have not defined a bean of type `CacheManager` or a `CacheResolver` named
. <<io#io.caching.provider.generic,Generic>>
. <<io#io.caching.provider.jcache,JCache (JSR-107)>> (EhCache 3, Hazelcast, Infinispan, and others)
. <<io#io.caching.provider.ehcache2,EhCache 2.x>>
. <<io#io.caching.provider.hazelcast,Hazelcast>>
. <<io#io.caching.provider.infinispan,Infinispan>>
. <<io#io.caching.provider.couchbase,Couchbase>>
@ -54,7 +53,7 @@ Use this property if you need to <<io#io.caching.provider.none,disable caching a
TIP: Use the `spring-boot-starter-cache` "`Starter`" to quickly add basic caching dependencies.
The starter brings in `spring-context-support`.
If you add dependencies manually, you must include `spring-context-support` in order to use the JCache, EhCache 2.x, or Caffeine support.
If you add dependencies manually, you must include `spring-context-support` in order to use the JCache or Caffeine support.
If the `CacheManager` is auto-configured by Spring Boot, you can further tune its configuration before it is fully initialized by exposing a bean that implements the `CacheManagerCustomizer` interface.
The following example sets a flag to say that `null` values should be passed down to the underlying map:
@ -112,22 +111,6 @@ No further customization is applied to it.
[[io.caching.provider.ehcache2]]
==== EhCache 2.x
https://www.ehcache.org/[EhCache] 2.x is used if a file named `ehcache.xml` can be found at the root of the classpath.
If EhCache 2.x is found, the `EhCacheCacheManager` provided by the `spring-boot-starter-cache` "`Starter`" is used to bootstrap the cache manager.
An alternate configuration file can be provided as well, as shown in the following example:
[source,yaml,indent=0,subs="verbatim",configprops,configblocks]
----
spring:
cache:
ehcache:
config: "classpath:config/another-config.xml"
----
[[io.caching.provider.hazelcast]]
==== Hazelcast
Spring Boot has <<io#io.hazelcast,general support for Hazelcast>>.

@ -16,9 +16,6 @@ def caches = [
"javax.cache:cache-api",
"org.ehcache:ehcache"
],
"ehcache2": [
"net.sf.ehcache:ehcache"
],
"hazelcast": [
"com.hazelcast:hazelcast",
"com.hazelcast:hazelcast-spring"

Loading…
Cancel
Save