基于接口 ErrorPageRegistrar
,具体代码如下
@Configuration
public class ErrorPageConfig implements ErrorPageRegistrar {
@Override
public void registerErrorPages(ErrorPageRegistry registry) {
ErrorPage error404=new ErrorPage(HttpStatus.NOT_FOUND,"/");
registry.addErrorPages(error404);
}
}