EmbeddedServletContainerCustomizer(spring 2 and spring boot 2) 更改为 WebServerFactoryCustomizer (spring 5 and spring boot 2)

EmbeddedServletContainerCustomizer(spring 2 and spring boot 2) changed to WebServerFactoryCustomizer (spring 5 and spring boot 2)

以下更改是否可以在 spring 5 中正常工作?

请建议正确的处理方式

Spring 2:

  @Bean
  public EmbeddedServletContainerCustomizer containerCustomizer()
  {
    return container -> 
    {
      container.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/not-found"));
    };
  }

spring 5 :

@Bean
  public WebServerFactoryCustomizer containerCustomizer()
  {
    return container -> 
    {
      TomcatServletWebServerFactory factory = new TomcatServletWebServerFactory();
    factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/not-found"));
      container = factory;
    };

  }

我参考了以下链接,

Spring Boot 2 中的等效代码如下:

@Bean
public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> webServerFactoryCustomizer() {
    return (factory) -> factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/not-found"));
}