Use the proper servlet classloader here.

Otherwise if samskivert.jar is loaded via the root classloader, this will fail
to find classes and resources in the servlet/webapp classloader. Let's not
require that samskivert.jar be duplicated into the webapp in cases where we're
doing complex things like hosting webapps inside larger app servers. That can
cause other fiddly problems with mismatched duplicate copies of classes.
This commit is contained in:
Michael Bayne
2025-12-02 15:58:13 -08:00
parent 1ddc109ed0
commit 65001875b5
@@ -185,7 +185,8 @@ public class DispatcherServlet extends HttpServlet
if (StringUtil.isBlank(appcl)) {
return new Application();
} else {
Class<?> appclass = Class.forName(appcl);
ClassLoader servletClassLoader = Thread.currentThread().getContextClassLoader();
Class<?> appclass = servletClassLoader.loadClass(appcl);
return (Application)appclass.getDeclaredConstructor().newInstance();
}
}
@@ -202,7 +203,8 @@ public class DispatcherServlet extends HttpServlet
"in the servlet configuration.");
}
// config util loads properties files from the classpath
Properties props = ConfigUtil.loadProperties(propsPath);
ClassLoader servletClassLoader = Thread.currentThread().getContextClassLoader();
Properties props = ConfigUtil.loadProperties(propsPath, servletClassLoader);
if (props == null) {
throw new IOException("Unable to load velocity properties " +
"from file '" + INIT_PROPS_KEY + "'.");
@@ -596,7 +598,8 @@ public class DispatcherServlet extends HttpServlet
*/
protected Logic instantiateLogic (String path, String lclass) {
try {
Class<?> pcl = Class.forName(lclass);
ClassLoader servletClassLoader = Thread.currentThread().getContextClassLoader();
Class<?> pcl = servletClassLoader.loadClass(lclass);
return (Logic)pcl.getDeclaredConstructor().newInstance();
} catch (ClassNotFoundException cnfe) {
// nothing interesting to report