Last active
August 30, 2017 21:29
-
-
Save ghillert/39536f902d7ac0017964 to your computer and use it in GitHub Desktop.
Spring Boot (embedded) and JSPs - Remove the last web.xml remnants
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
... | |
public class DevNexusApplication implements EmbeddedServletContainerCustomizer { | |
... | |
@Override | |
public void customize(ConfigurableEmbeddedServletContainer container) { | |
if(container instanceof TomcatEmbeddedServletContainerFactory) { | |
final TomcatEmbeddedServletContainerFactory tomcatEmbeddedServletContainerFactory | |
= (TomcatEmbeddedServletContainerFactory) container; | |
tomcatEmbeddedServletContainerFactory.addContextCustomizers( | |
new TomcatContextCustomizer() { | |
@Override | |
public void customize(Context context) { | |
context.addWelcomeFile("index.jsp"); | |
final ErrorPage throwableErrorPage = new ErrorPage(); | |
throwableErrorPage.setExceptionType("java.lang.Throwable"); | |
throwableErrorPage.setLocation("/WEB-INF/jsp/error/error.jsp"); | |
final ErrorPage errorPage403 = new ErrorPage(); | |
errorPage403.setErrorCode(403); | |
errorPage403.setLocation("/WEB-INF/jsp/error/403.jsp"); | |
final ErrorPage errorPage404 = new ErrorPage(); | |
errorPage404.setErrorCode(404); | |
errorPage404.setLocation("/WEB-INF/jsp/error/404.jsp"); | |
final ErrorPage errorPage500 = new ErrorPage(); | |
errorPage500.setErrorCode(500); | |
errorPage500.setLocation("/WEB-INF/jsp/error/500.jsp"); | |
context.addErrorPage(errorPage500); | |
context.addErrorPage(errorPage404); | |
context.addErrorPage(errorPage403); | |
context.addErrorPage(throwableErrorPage); | |
final Collection<JspPropertyGroupDescriptor> jspPropertyGroups = new ArrayList<>(); | |
final Collection<TaglibDescriptor> taglibs = new ArrayList<>(); | |
final JspPropertyGroup group = new JspPropertyGroup(); | |
group.addUrlPattern("*.jsp"); | |
group.setPageEncoding("UTF-8"); | |
final JspPropertyGroupDescriptor descriptor = new JspPropertyGroupDescriptorImpl(group); | |
jspPropertyGroups.add(descriptor); | |
final JspConfigDescriptor jspConfigDescriptor = new JspConfigDescriptorImpl(jspPropertyGroups, taglibs); | |
context.setJspConfigDescriptor(jspConfigDescriptor); | |
} | |
} | |
); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment