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
This commit is contained in:
committed by
Stephane Nicoll
parent
f745f20c8c
commit
76b9d0d243
@@ -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
|
||||
|
||||
Reference in New Issue
Block a user