From e1df2f886b943afa775f65de30ba1ac869f52272 Mon Sep 17 00:00:00 2001 From: zhaojun <873019219@qq.com> Date: Wed, 13 Jul 2022 20:18:48 +0800 Subject: [PATCH] =?UTF-8?q?:bug:=20=E4=BF=AE=E5=A4=8D=20url=20=E8=B7=AF?= =?UTF-8?q?=E5=BE=84=E4=B8=AD=E5=B8=A6=20.=20=E8=AE=BF=E9=97=AE=20404=20?= =?UTF-8?q?=E7=9A=84=20bug?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../zfile/common/config/WebMvcConfig.java | 20 +++++++++++++++++++ 1 file changed, 20 insertions(+) diff --git a/src/main/java/im/zhaojun/zfile/common/config/WebMvcConfig.java b/src/main/java/im/zhaojun/zfile/common/config/WebMvcConfig.java index 6bca490..591c142 100644 --- a/src/main/java/im/zhaojun/zfile/common/config/WebMvcConfig.java +++ b/src/main/java/im/zhaojun/zfile/common/config/WebMvcConfig.java @@ -1,12 +1,19 @@ package im.zhaojun.zfile.common.config; import org.springframework.boot.web.embedded.tomcat.TomcatServletWebServerFactory; +import org.springframework.boot.web.server.ConfigurableWebServerFactory; +import org.springframework.boot.web.server.ErrorPage; +import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.boot.web.servlet.server.ServletWebServerFactory; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.format.FormatterRegistry; +import org.springframework.http.HttpStatus; import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; +import java.util.HashSet; +import java.util.Set; + /** * ZFile Web 相关配置. * @@ -41,4 +48,17 @@ public class WebMvcConfig implements WebMvcConfigurer { return webServerFactory; } + + @Bean + public WebServerFactoryCustomizer webServerFactoryCustomizer(){ + return factory -> { + ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/index.html"); + ErrorPage error200Page = new ErrorPage(HttpStatus.OK, "/index.html"); + Set errorPages = new HashSet<>(); + errorPages.add(error404Page); + errorPages.add(error200Page); + factory.setErrorPages(errorPages); + }; + } + } \ No newline at end of file