Merge branch '1.5.x' into 2.0.x

pull/13388/head
Stephane Nicoll 7 years ago
commit a9b2826c26

@ -1,5 +1,5 @@
/*
* Copyright 2012-2017 the original author or authors.
* Copyright 2012-2018 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.
@ -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,
@ -85,6 +88,11 @@ class JCacheCacheConfiguration {
this.cachePropertiesCustomizers = cachePropertiesCustomizers.getIfAvailable();
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;
}
@Bean
public JCacheCacheManager cacheManager(CacheManager jCacheCacheManager) {
JCacheCacheManager cacheManager = new JCacheCacheManager(jCacheCacheManager);
@ -113,9 +121,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) {

@ -469,6 +469,20 @@ public class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationT
.hasMessageContaining(configLocation));
}
@Test
public void jCacheCacheUseBeanClassLoader() {
String cachingProviderFqn = MockCachingProvider.class.getName();
this.contextRunner.withUserConfiguration(DefaultCacheConfiguration.class)
.withPropertyValues("spring.cache.type=jcache",
"spring.cache.jcache.provider=" + cachingProviderFqn)
.run((context) -> {
JCacheCacheManager cacheManager = getCacheManager(context,
JCacheCacheManager.class);
assertThat(cacheManager.getCacheManager().getClassLoader())
.isEqualTo(context.getClassLoader());
});
}
@Test
public void hazelcastCacheExplicit() {
this.contextRunner

Loading…
Cancel
Save