以下更改是否在春季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;
};
}
我引用了以下链接,
答案 0 :(得分:0)
Spring Boot 2中的等效代码如下:
@Bean
public WebServerFactoryCustomizer<ConfigurableServletWebServerFactory> webServerFactoryCustomizer() {
return (factory) -> factory.addErrorPages(new ErrorPage(HttpStatus.NOT_FOUND, "/not-found"));
}