Spring Boot1.5X升级到2.0

配置文件

大量的Servlet专属的server.* properties被移到了server.servlet下

拦截器

public class MyWebMvcConfigurerAdapter implements WebMvcConfigurer

静态资源被拦截

spring boot 2.0则对静态资源也进行了拦截

全局异常特殊处理

设置不同的状态码,转发到不同的页面上

@Configuration
public class ContainerConfig implements ErrorPageRegistrar {

    @Override
    public void registerErrorPages(ErrorPageRegistry registry) {
        ErrorPage[] errorPages = new ErrorPage[2];
        errorPages[0] = new ErrorPage(HttpStatus.INTERNAL_SERVER_ERROR, "/error/500");
        errorPages[1] = new ErrorPage(HttpStatus.NOT_FOUND, "/error/404");
        registry.addErrorPages(errorPages);
    }
}