search

Home  >  Q&A  >  body text

java - Spring Boot 异常页面配置问题

@Configuration
public class WebConfig {

    @Bean
    public EmbeddedServletContainerCustomizer containerCustomizer() {
 
        return new EmbeddedServletContainerCustomizer() {
            @Override
            public void customize(ConfigurableEmbeddedServletContainer container) {
                ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404");
                container.addErrorPages(error404Page);
            }
        };
    }
}

404所在位置:

P.S 这样配置的话,系统无法正常跳转到指定 404 页面,求助~

巴扎黑巴扎黑2889 days ago251

reply all(1)I'll reply

  • PHP中文网

    PHP中文网2017-04-17 17:57:43

    SOLVED:
    The reason is
    ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/404");

    Unable to route to the specified page, you need to define a controller and use SpringMVC's DispatcherServlet to distribute routing to the specified page.

    reply
    0
  • Cancelreply