Skip to content

Commit c67aedd

Browse files
committed
Polish "Retrieve javax.cache.CacheManager using Bean ClassLoader"
Closes gh-13338
1 parent 76b9d0d commit c67aedd

File tree

2 files changed

+16
-6
lines changed

2 files changed

+16
-6
lines changed

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2017 the original author or authors.
2+
* Copyright 2012-2018 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -88,6 +88,11 @@ class JCacheCacheConfiguration implements BeanClassLoaderAware {
8888
this.cachePropertiesCustomizers = cachePropertiesCustomizers.getIfAvailable();
8989
}
9090

91+
@Override
92+
public void setBeanClassLoader(ClassLoader classLoader) {
93+
this.beanClassLoader = classLoader;
94+
}
95+
9196
@Bean
9297
public JCacheCacheManager cacheManager(CacheManager jCacheCacheManager) {
9398
JCacheCacheManager cacheManager = new JCacheCacheManager(jCacheCacheManager);
@@ -154,11 +159,6 @@ private void customize(CacheManager cacheManager) {
154159
}
155160
}
156161

157-
@Override
158-
public void setBeanClassLoader(ClassLoader classLoader) {
159-
this.beanClassLoader = classLoader;
160-
}
161-
162162
/**
163163
* Determine if JCache is available. This either kicks in if a provider is available
164164
* as defined per {@link JCacheProviderAvailableCondition} or if a

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

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,16 @@ public void jCacheCacheWithWrongConfig() {
374374
"spring.cache.jcache.config=" + configLocation);
375375
}
376376

377+
@Test
378+
public void jCacheCacheUseBeanClassLoader() {
379+
String cachingProviderFqn = MockCachingProvider.class.getName();
380+
load(DefaultCacheConfiguration.class, "spring.cache.type=jcache",
381+
"spring.cache.jcache.provider=" + cachingProviderFqn);
382+
JCacheCacheManager cacheManager = validateCacheManager(JCacheCacheManager.class);
383+
assertThat(cacheManager.getCacheManager().getClassLoader())
384+
.isEqualTo(this.context.getClassLoader());
385+
}
386+
377387
@Test
378388
public void ehcacheCacheWithCaches() {
379389
load(DefaultCacheConfiguration.class, "spring.cache.type=ehcache");

0 commit comments

Comments
 (0)