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