Commit 76b9d0d2 authored by Martin Theiss's avatar Martin Theiss Committed by Stephane Nicoll

Retrieve javax.cache.CacheManager using Bean ClassLoader

This commit uses the bean's classloader to retrieve the CacheManager to
prevent issues with off-heap serialization.

See gh-13338
parent f745f20c
......@@ -26,6 +26,7 @@ import javax.cache.Caching;
import javax.cache.configuration.MutableConfiguration;
import javax.cache.spi.CachingProvider;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionMessage;
......@@ -61,7 +62,7 @@ import org.springframework.util.StringUtils;
@Conditional({ CacheCondition.class,
JCacheCacheConfiguration.JCacheAvailableCondition.class })
@Import(HazelcastJCacheCustomizationConfiguration.class)
class JCacheCacheConfiguration {
class JCacheCacheConfiguration implements BeanClassLoaderAware {
private final CacheProperties cacheProperties;
......@@ -73,6 +74,8 @@ class JCacheCacheConfiguration {
private final List<JCachePropertiesCustomizer> cachePropertiesCustomizers;
private ClassLoader beanClassLoader;
JCacheCacheConfiguration(CacheProperties cacheProperties,
CacheManagerCustomizers customizers,
ObjectProvider<javax.cache.configuration.Configuration<?, ?>> defaultCacheConfiguration,
......@@ -113,9 +116,9 @@ class JCacheCacheConfiguration {
.resolveConfigLocation(this.cacheProperties.getJcache().getConfig());
if (configLocation != null) {
return cachingProvider.getCacheManager(configLocation.getURI(),
cachingProvider.getDefaultClassLoader(), properties);
this.beanClassLoader, properties);
}
return cachingProvider.getCacheManager(null, null, properties);
return cachingProvider.getCacheManager(null, this.beanClassLoader, properties);
}
private CachingProvider getCachingProvider(String cachingProviderFqn) {
......@@ -151,6 +154,11 @@ class JCacheCacheConfiguration {
}
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;
}
/**
* Determine if JCache is available. This either kicks in if a provider is available
* as defined per {@link JCacheProviderAvailableCondition} or if a
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment