Skip to content

Commit 5ef6903

Browse files
committed
Make EmbeddedVelocityToolboxView work in servlet container deployments
EmbeddedVelocityToolboxView is used with both embedded containers and when a Spring Boot application is deployed to a servlet container. It process the ServletContext to intercept calls to getResource so that it can load Velocity’s toolbox.xml file from within an executable jar. Previously, when it created the proxy, it didn’t specify the ClassLoader to use. This resulted in the proxy being created using the ClassLoader that loaded the Class that is being proxied. This fails when the application is deployed to a ServletContainer as the ClassLoader that loaded the ServletContext implementation is the container’s ClassLoader and it cannot see the classes that are specific to the web application. This commit updates EmbeddedVelocityToolboxView to specify the ClassLoader to use when creating the proxy. It specifies its own ClassLoader thereby ensuring that the proxy creation can load application-specific classes. Fixes spring-projectsgh-4967
1 parent 2ceadd7 commit 5ef6903

File tree

1 file changed

+5
-4
lines changed

1 file changed

+5
-4
lines changed

spring-boot/src/main/java/org/springframework/boot/web/servlet/view/velocity/EmbeddedVelocityToolboxView.java

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2012-2015 the original author or authors.
2+
* Copyright 2012-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.
@@ -34,10 +34,11 @@
3434

3535
/**
3636
* Extended version of {@link VelocityToolboxView} that can load toolbox locations from
37-
* the classpath as well as the servlet context. This is useful when run an embedded web
38-
* server.
37+
* the classpath as well as the servlet context. This is useful when running in an
38+
* embedded web server.
3939
*
4040
* @author Phillip Webb
41+
* @author Andy Wilkinson
4142
* @since 1.2.5
4243
*/
4344
@SuppressWarnings("deprecation")
@@ -69,7 +70,7 @@ private ServletContext getToolboxConfigFileAwareServletContext() {
6970
ProxyFactory factory = new ProxyFactory();
7071
factory.setTarget(getServletContext());
7172
factory.addAdvice(new GetResourceMethodInterceptor(getToolboxConfigLocation()));
72-
return (ServletContext) factory.getProxy();
73+
return (ServletContext) factory.getProxy(getClass().getClassLoader());
7374
}
7475

7576
/**

0 commit comments

Comments
 (0)