使用Spring Boot&Spring MVC,您可以在resources / public下创建一个错误文件夹,并放置您的客户错误页面。spring会接他们的。
src/+- main/ +- java/ | + <source pre> +- resources/ +- public/+- error/| +- 404.html+- <other public assets>
如果您不使用Spring MVC,则必须通过实现自己的错误页面注册器来注册错误页面。
@Beanpublic ErrorPageRegistrar errorPageRegistrar(){ return new MyErrorPageRegistrar();}private static class MyErrorPageRegistrar implements ErrorPageRegistrar { // Register your error pages and url paths. @Override public void registerErrorPages(ErrorPageRegistry registry) { registry.addErrorPages(new ErrorPage(HttpStatus.BAD_REQUEST, "/400")); }}http://docs.spring.io/spring-boot/docs/current/reference/htmlsingle/#boot-
features-error-handling-custom-error-pages



