Undertow is another alternative for using an embedded container with Spring Boot. You can find general information in the Spring Boot reference guide chapter Use Undertow instead of Tomcat. While I was working on updating the Spring Boot documentation regarding the JSP support for Tomcat, I noticed the following line in the reference guide for Spring Boot
"Undertow does not support JSPs."
Being a good citizen, I dug a little deeper and discovered the Undertow JSP sample application by Chris Grieger. It turns out that Undertow has indeed JSP support by using jastow, which is a Jasper fork for Undertow. The key was to adapt the Undertow JSP sample application for Spring Boot. Doing so was actually fairly straightforward. The actual Undertow configuration uses Spring Boot`s
The full source is available in the
JspDemoApplication class. The main issue is more or less the retrieval and configuration of the used Taglibraries. The Undertow JSP sample provides the TldLocator class, which does the heavy lifting. For our example, I am adapting that class so that it works in the context of Spring Boot. In Spring Boot we are dealing with über-Jars, meaning the resulting executable jar file will contain other jar files representing its dependencies.
Spring provides some nifty helpers to retrieve the needed Tag Library Descriptors (TLD) files. In
TldLocator#createTldInfos I use a
ResourcePatternResolver, specifically a
PathMatchingResourcePatternResolver with a location pattern of
Don’t forget the asterix right after
classpath*: allows you to retrieve multiple class path resources with the same name. It will also retrieve resources across multiple jar files. This is an extremely useful feature. For more information please see the relevant JavaDocs for PathMatchingResourcePatternResolver.
Once we have the TLD resources, they will be parsed and ultimately used to create a collection of
org.apache.jasper.deploy.TagLibraryInfo. With those at hand, we create a JSP deployment for Undertow using the DeploymentInfo and the
And that’s it. Simply build and run the application and you should have a working JSP-based application.
In your console you should start seeing how the application starts up.
Once started, open your browser and go to the following Url http://localhost:8080/.
You can find the full source-code for this sample at https://github.com/ghillert/spring-boot-jsp-demo