@@ -427,6 +427,8 @@ protected EmbeddedCacheManager createCacheManager(
427
427
DEF_INFINISPAN_CONFIG_RESOURCE
428
428
);
429
429
final FileLookup fileLookup = FileLookupFactory .newInstance ();
430
+ //The classloader of the current module:
431
+ final ClassLoader infinispanClassLoader = InfinispanRegionFactory .class .getClassLoader ();
430
432
431
433
return serviceRegistry .getService ( ClassLoaderService .class ).workWithClassLoader (
432
434
new ClassLoaderService .Work <EmbeddedCacheManager >() {
@@ -438,12 +440,12 @@ public EmbeddedCacheManager doWork(ClassLoader classLoader) {
438
440
if ( is == null ) {
439
441
// when it's not a user-provided configuration file, it might be a default configuration file,
440
442
// and if that's included in [this] module might not be visible to the ClassLoaderService:
441
- classLoader = this . getClass (). getClassLoader () ;
443
+ classLoader = infinispanClassLoader ;
442
444
// This time use lookupFile*Strict* so to provide an exception if we can't find it yet:
443
445
is = FileLookupFactory .newInstance ().lookupFileStrict ( configLoc , classLoader );
444
446
}
445
- final ParserRegistry parserRegistry = new ParserRegistry ( classLoader );
446
- final ConfigurationBuilderHolder holder = parserRegistry . parse ( is );
447
+ final ParserRegistry parserRegistry = new ParserRegistry ( infinispanClassLoader );
448
+ final ConfigurationBuilderHolder holder = parseWithOverridenClassLoader ( parserRegistry , is , infinispanClassLoader );
447
449
448
450
// Override global jmx statistics exposure
449
451
final String globalStats = extractProperty (
@@ -462,10 +464,28 @@ public EmbeddedCacheManager doWork(ClassLoader classLoader) {
462
464
throw new CacheException ( "Unable to create default cache manager" , e );
463
465
}
464
466
}
467
+
465
468
}
466
469
);
467
470
}
468
471
472
+ private static ConfigurationBuilderHolder parseWithOverridenClassLoader (ParserRegistry configurationParser , InputStream is , ClassLoader infinispanClassLoader ) {
473
+ // Infinispan requires the context ClassLoader to have full visibility on all
474
+ // its components and eventual extension points even *during* configuration parsing.
475
+ final Thread currentThread = Thread .currentThread ();
476
+ final ClassLoader originalContextClassLoader = currentThread .getContextClassLoader ();
477
+ try {
478
+ currentThread .setContextClassLoader ( infinispanClassLoader );
479
+ ConfigurationBuilderHolder builderHolder = configurationParser .parse ( is );
480
+ // Workaround Infinispan's ClassLoader strategies to bend to our will:
481
+ builderHolder .getGlobalConfigurationBuilder ().classLoader ( infinispanClassLoader );
482
+ return builderHolder ;
483
+ }
484
+ finally {
485
+ currentThread .setContextClassLoader ( originalContextClassLoader );
486
+ }
487
+ }
488
+
469
489
protected EmbeddedCacheManager createCacheManager (ConfigurationBuilderHolder holder ) {
470
490
return new DefaultCacheManager ( holder , true );
471
491
}
0 commit comments