Commit 99f0270f authored by Stephane Nicoll's avatar Stephane Nicoll

Merge branch '2.0.x'

parents c973488c a9b2826c
/* /*
* 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"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
...@@ -26,6 +26,7 @@ import javax.cache.Caching; ...@@ -26,6 +26,7 @@ import javax.cache.Caching;
import javax.cache.configuration.MutableConfiguration; import javax.cache.configuration.MutableConfiguration;
import javax.cache.spi.CachingProvider; import javax.cache.spi.CachingProvider;
import org.springframework.beans.factory.BeanClassLoaderAware;
import org.springframework.beans.factory.ObjectProvider; import org.springframework.beans.factory.ObjectProvider;
import org.springframework.boot.autoconfigure.condition.AnyNestedCondition; import org.springframework.boot.autoconfigure.condition.AnyNestedCondition;
import org.springframework.boot.autoconfigure.condition.ConditionMessage; import org.springframework.boot.autoconfigure.condition.ConditionMessage;
...@@ -61,7 +62,7 @@ import org.springframework.util.StringUtils; ...@@ -61,7 +62,7 @@ import org.springframework.util.StringUtils;
@Conditional({ CacheCondition.class, @Conditional({ CacheCondition.class,
JCacheCacheConfiguration.JCacheAvailableCondition.class }) JCacheCacheConfiguration.JCacheAvailableCondition.class })
@Import(HazelcastJCacheCustomizationConfiguration.class) @Import(HazelcastJCacheCustomizationConfiguration.class)
class JCacheCacheConfiguration { class JCacheCacheConfiguration implements BeanClassLoaderAware {
private final CacheProperties cacheProperties; private final CacheProperties cacheProperties;
...@@ -73,6 +74,8 @@ class JCacheCacheConfiguration { ...@@ -73,6 +74,8 @@ class JCacheCacheConfiguration {
private final List<JCachePropertiesCustomizer> cachePropertiesCustomizers; private final List<JCachePropertiesCustomizer> cachePropertiesCustomizers;
private ClassLoader beanClassLoader;
JCacheCacheConfiguration(CacheProperties cacheProperties, JCacheCacheConfiguration(CacheProperties cacheProperties,
CacheManagerCustomizers customizers, CacheManagerCustomizers customizers,
ObjectProvider<javax.cache.configuration.Configuration<?, ?>> defaultCacheConfiguration, ObjectProvider<javax.cache.configuration.Configuration<?, ?>> defaultCacheConfiguration,
...@@ -85,6 +88,11 @@ class JCacheCacheConfiguration { ...@@ -85,6 +88,11 @@ class JCacheCacheConfiguration {
this.cachePropertiesCustomizers = cachePropertiesCustomizers.getIfAvailable(); this.cachePropertiesCustomizers = cachePropertiesCustomizers.getIfAvailable();
} }
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;
}
@Bean @Bean
public JCacheCacheManager cacheManager(CacheManager jCacheCacheManager) { public JCacheCacheManager cacheManager(CacheManager jCacheCacheManager) {
JCacheCacheManager cacheManager = new JCacheCacheManager(jCacheCacheManager); JCacheCacheManager cacheManager = new JCacheCacheManager(jCacheCacheManager);
...@@ -113,9 +121,9 @@ class JCacheCacheConfiguration { ...@@ -113,9 +121,9 @@ class JCacheCacheConfiguration {
.resolveConfigLocation(this.cacheProperties.getJcache().getConfig()); .resolveConfigLocation(this.cacheProperties.getJcache().getConfig());
if (configLocation != null) { if (configLocation != null) {
return cachingProvider.getCacheManager(configLocation.getURI(), 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) { private CachingProvider getCachingProvider(String cachingProviderFqn) {
......
...@@ -469,6 +469,20 @@ public class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationT ...@@ -469,6 +469,20 @@ public class CacheAutoConfigurationTests extends AbstractCacheAutoConfigurationT
.hasMessageContaining(configLocation)); .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 @Test
public void hazelcastCacheExplicit() { public void hazelcastCacheExplicit() {
this.contextRunner this.contextRunner
......
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