I have a spring boot embedded tomcat(spring boot v2.4) application with this context path (server.servlet.context-path=/store). now when I go to this address (https://localhost:8080/sto), the 404 Tomcat page is displayed. how can I customize this 404 page Tomcat? I use jsp and war packaging. to do this, I created a project in the simplest possible way and configured it according to this document https://docs.spring.io/spring-boot/docs/current/reference/html/features.html#features.developing-web-applications.spring-mvc.error-handling.error-pages-without-spring-mvc
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-tomcat</artifactId>
<scope>provided</scope>
</dependency>
##########################
@Bean
public ErrorPageRegistrar errorPageRegistrar() {
return this::registerErrorPages;
}
private void registerErrorPages(ErrorPageRegistry registry) {
registry.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND,"/error.jsp"));
}
and I put an error.jsp in the webapp folder, But it does not work. is this the right way?
Comment From: wilkinsona
Tomcat configures error pages on a per-context basis. You've mapped the context to /store
so the error pages will only take effect for errors that occur when handling requests to /store/*
.
Rather than configuring the entire context's path, you may want to consider changing the dispatcher servlet's path using spring.mvc.servlet.path
instead.
If you have any further questions, please follow up on Stack Overflow or Gitter. As mentioned in the guidelines for contributing, we prefer to use GitHub issues only for bugs and enhancements.