SpringBoot异常处理之SimpleMappingExceptionResolver

在springmvc的xml配置文件中的配置:

SpringBoot异常处理之SimpleMappingExceptionResolver_第1张图片

但是springboot没的xml配置文件的,但有对应的配置类:

@Configuration
public class MyErrorConfig {
    @Bean
    public SimpleMappingExceptionResolver getExBean(){
        SimpleMappingExceptionResolver bean = new SimpleMappingExceptionResolver();
        Properties mapper = new Properties();
        mapper.put("java.lang.NullPointerException","error");
        mapper.put("java.lang.ArithmeticException","error");
        bean.setExceptionMappings(mapper);
    }
}

 这个配置会默认把异常对想以exception名字注入到视图。

你可能感兴趣的:(Java,代码笔记,spring,boot,java,后端)