EmbeddedServletContainerCustomizer(Spring 2和Spring Boot 2)已更改为WebServerFactoryCustomizer(Spring 5和Spring Boot 2)

时间:2019-03-28 14:11:23

标签: spring-boot spring-security embeddedwebserver

以下更改是否在春季5可以正常使用?

请提出正确的操作方法

春季2:

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

春天5:

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

  }

我引用了以下链接,

EmbeddedServletContainerCustomizer in spring boot 2.0

1 个答案:

答案 0 :(得分:0)

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

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