Skip to content

Commit 405e74b

Browse files
committed
GenericApplicationContext picks up ClassLoader from custom ResourceLoader
Issue: SPR-14626
1 parent f3f691c commit 405e74b

File tree

1 file changed

+21
-1
lines changed

1 file changed

+21
-1
lines changed

spring-context/src/main/java/org/springframework/context/support/GenericApplicationContext.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2002-2015 the original author or authors.
2+
* Copyright 2002-2016 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.
@@ -91,6 +91,8 @@ public class GenericApplicationContext extends AbstractApplicationContext implem
9191

9292
private ResourceLoader resourceLoader;
9393

94+
private boolean customClassLoader = false;
95+
9496
private final AtomicBoolean refreshed = new AtomicBoolean();
9597

9698

@@ -198,6 +200,10 @@ public void setResourceLoader(ResourceLoader resourceLoader) {
198200
}
199201

200202

203+
//---------------------------------------------------------------------
204+
// ResourceLoader / ResourcePatternResolver override if necessary
205+
//---------------------------------------------------------------------
206+
201207
/**
202208
* This implementation delegates to this context's ResourceLoader if set,
203209
* falling back to the default superclass behavior else.
@@ -225,6 +231,20 @@ public Resource[] getResources(String locationPattern) throws IOException {
225231
return super.getResources(locationPattern);
226232
}
227233

234+
@Override
235+
public void setClassLoader(ClassLoader classLoader) {
236+
super.setClassLoader(classLoader);
237+
this.customClassLoader = true;
238+
}
239+
240+
@Override
241+
public ClassLoader getClassLoader() {
242+
if (this.resourceLoader != null && !this.customClassLoader) {
243+
return this.resourceLoader.getClassLoader();
244+
}
245+
return super.getClassLoader();
246+
}
247+
228248

229249
//---------------------------------------------------------------------
230250
// Implementations of AbstractApplicationContext's template methods

0 commit comments

Comments
 (0)