I am running the Spring boot application inside a separate tomcat instance and I am trying to override the error pages. In my opinion, Spring provides an ErrorPageFilter filter that allows me to simply set up error pages, as usual, for the Springs EmbeddedServletContainerCustomizer to handle this case.
So, I have a standard auto configuration / servlet initializer in one class:
@Configuration @ComponentScan @EnableAutoConfiguration(exclude = [ GroovyTemplateAutoConfiguration, SecurityAutoConfiguration, ErrorMvcAutoConfiguration, JmxAutoConfiguration ] ) class Application extends SpringBootServletInitializer { @Override protected SpringApplicationBuilder configure( SpringApplicationBuilder application ) { application.sources( Application ) }
(I use the same class for autoconfiguration and servlet init, so I just pass my Application class in the configure method)
Looking at the source code of SpringBootServletInitializer , it looks like the ErrorPageFilter class is ErrorPageFilter added, just extending this class here. I turned off ErrorMvcAutoConfiguration - but then again, looking at this source code, it looks like it's just setting the default error pages, and not setting anything up with ErrorPageFilter .
Then I have an error configuration file:
@Configuration class ErrorConfiguration implements EmbeddedServletContainerCustomizer { @Override public void customize( ConfigurableEmbeddedServletContainer container ) { container.addErrorPages(new ErrorPage( HttpStatus.NOT_FOUND, "/errors/404" )) }
However, if I just find an invalid URL, and I DispatcherServlet cannot find a match, then I just get tomcats / 404.html - not my view is associated with " /errors/404 " (I have this path mapped to the timeline view template which works fine - if I go to / errors / 404, it displays fine)
Any ideas why my custom error page is not working? tracking the logs, I get a line about setting ErrorPageFilter and setting ok when the application starts, but then no mention of the filter does anything when the request arrives.
spring spring-boot spring-mvc tomcat
rhinds
source share