package lsgwr.exam.config; import org.springframework.boot.web.server.ConfigurableWebServerFactory; import org.springframework.boot.web.server.ErrorPage; import org.springframework.boot.web.server.WebServerFactoryCustomizer; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; import org.springframework.http.HttpStatus; @Configuration public class ServletConfig { // 创建一个WebServerFactoryCustomizer bean,用于自定义WebServerFactory @Bean public WebServerFactoryCustomizer webServerFactoryCustomizer() { // 返回一个lambda表达式,用于自定义WebServerFactory return factory -> { // 创建一个ErrorPage对象,用于处理404错误 ErrorPage error404Page = new ErrorPage(HttpStatus.NOT_FOUND, "/"); // 将ErrorPage对象添加到WebServerFactory中 factory.addErrorPages(error404Page); }; } }