2626import javax .cache .configuration .MutableConfiguration ;
2727import javax .cache .spi .CachingProvider ;
2828
29+ import org .springframework .beans .factory .BeanClassLoaderAware ;
2930import org .springframework .beans .factory .ObjectProvider ;
3031import org .springframework .boot .autoconfigure .condition .AnyNestedCondition ;
3132import org .springframework .boot .autoconfigure .condition .ConditionMessage ;
6162@ Conditional ({ CacheCondition .class ,
6263 JCacheCacheConfiguration .JCacheAvailableCondition .class })
6364@ Import (HazelcastJCacheCustomizationConfiguration .class )
64- class JCacheCacheConfiguration {
65+ class JCacheCacheConfiguration implements BeanClassLoaderAware {
6566
6667 private final CacheProperties cacheProperties ;
6768
@@ -73,6 +74,8 @@ class JCacheCacheConfiguration {
7374
7475 private final List <JCachePropertiesCustomizer > cachePropertiesCustomizers ;
7576
77+ private ClassLoader beanClassLoader ;
78+
7679 JCacheCacheConfiguration (CacheProperties cacheProperties ,
7780 CacheManagerCustomizers customizers ,
7881 ObjectProvider <javax .cache .configuration .Configuration <?, ?>> defaultCacheConfiguration ,
@@ -113,9 +116,9 @@ private CacheManager createCacheManager() throws IOException {
113116 .resolveConfigLocation (this .cacheProperties .getJcache ().getConfig ());
114117 if (configLocation != null ) {
115118 return cachingProvider .getCacheManager (configLocation .getURI (),
116- cachingProvider . getDefaultClassLoader () , properties );
119+ this . beanClassLoader , properties );
117120 }
118- return cachingProvider .getCacheManager (null , null , properties );
121+ return cachingProvider .getCacheManager (null , this . beanClassLoader , properties );
119122 }
120123
121124 private CachingProvider getCachingProvider (String cachingProviderFqn ) {
@@ -151,6 +154,11 @@ private void customize(CacheManager cacheManager) {
151154 }
152155 }
153156
157+ @ Override
158+ public void setBeanClassLoader (ClassLoader classLoader ) {
159+ this .beanClassLoader = classLoader ;
160+ }
161+
154162 /**
155163 * Determine if JCache is available. This either kicks in if a provider is available
156164 * as defined per {@link JCacheProviderAvailableCondition} or if a
0 commit comments