GenericApplicationContext picks up ClassLoader from custom ResourceLoader

Issue: SPR-14626
master
Juergen Hoeller 8 years ago
parent f3f691cc37
commit 405e74b6ae
  1. 22
      spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2015 the original author or authors. * Copyright 2002-2016 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.
@ -91,6 +91,8 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
private ResourceLoader resourceLoader; private ResourceLoader resourceLoader;
private boolean customClassLoader = false;
private final AtomicBoolean refreshed = new AtomicBoolean(); private final AtomicBoolean refreshed = new AtomicBoolean();
@ -198,6 +200,10 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
} }
//---------------------------------------------------------------------
// ResourceLoader / ResourcePatternResolver override if necessary
//---------------------------------------------------------------------
/** /**
* This implementation delegates to this context's ResourceLoader if set, * This implementation delegates to this context's ResourceLoader if set,
* falling back to the default superclass behavior else. * falling back to the default superclass behavior else.
@ -225,6 +231,20 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
return super.getResources(locationPattern); return super.getResources(locationPattern);
} }
@Override
public void setClassLoader(ClassLoader classLoader) {
super.setClassLoader(classLoader);
this.customClassLoader = true;
}
@Override
public ClassLoader getClassLoader() {
if (this.resourceLoader != null && !this.customClassLoader) {
return this.resourceLoader.getClassLoader();
}
return super.getClassLoader();
}
//--------------------------------------------------------------------- //---------------------------------------------------------------------
// Implementations of AbstractApplicationContext's template methods // Implementations of AbstractApplicationContext's template methods

Loading…
Cancel
Save