举个栗子: 自定义异常处理类CustomExceptionResolver,如下: 将CustomExceptionResolver注册为一个Bean将CustomExceptionResolver注册为Bean就比较简单了,可以直接在类上添加@Component注解,也可以通过Java进行配置,如下: public class WebMvcConfig extends WebMvcConfigurerAdapter { }