Browse Source

Polish "Retrieve javax.cache.CacheManager using Bean ClassLoader"

Closes gh-13338
pull/13429/head
Stephane Nicoll 8 years ago
parent
commit
c67aedd8bc
  1. 12
      spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.java
  2. 10
      spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java

12
spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/cache/JCacheCacheConfiguration.java vendored

@ -1,5 +1,5 @@ @@ -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.
@ -88,6 +88,11 @@ class JCacheCacheConfiguration implements BeanClassLoaderAware { @@ -88,6 +88,11 @@ class JCacheCacheConfiguration implements BeanClassLoaderAware {
this.cachePropertiesCustomizers = cachePropertiesCustomizers.getIfAvailable();
}
@Override
public void setBeanClassLoader(ClassLoader classLoader) {
this.beanClassLoader = classLoader;
}
@Bean
public JCacheCacheManager cacheManager(CacheManager jCacheCacheManager) {
JCacheCacheManager cacheManager = new JCacheCacheManager(jCacheCacheManager);
@ -154,11 +159,6 @@ class JCacheCacheConfiguration implements BeanClassLoaderAware { @@ -154,11 +159,6 @@ class JCacheCacheConfiguration implements BeanClassLoaderAware {
}
}
@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

10
spring-boot-autoconfigure/src/test/java/org/springframework/boot/autoconfigure/cache/CacheAutoConfigurationTests.java vendored

@ -374,6 +374,16 @@ public class CacheAutoConfigurationTests { @@ -374,6 +374,16 @@ public class CacheAutoConfigurationTests {
"spring.cache.jcache.config=" + configLocation);
}
@Test
public void jCacheCacheUseBeanClassLoader() {
String cachingProviderFqn = MockCachingProvider.class.getName();
load(DefaultCacheConfiguration.class, "spring.cache.type=jcache",
"spring.cache.jcache.provider=" + cachingProviderFqn);
JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
assertThat(cacheManager.getCacheManager().getClassLoader())
.isEqualTo(this.context.getClassLoader());
}
@Test
public void ehcacheCacheWithCaches() {
load(DefaultCacheConfiguration.class, "spring.cache.type=ehcache");

Loading…
Cancel
Save