配置异常类扫描包
<!--扫描包-->
<context:component-scan base-package="com.port.socket" use-default-filters="false">
<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
<context:include-filter type="annotation" expression="org.springframework.web.bind.annotation.ControllerAdvice"/>
</context:component-scan>
//控制层异常类
//@ControllerAdvice异常类注解
@ControllerAdvice
public class CommException{
//设置要拦截的移除 value={异常的Class文件}
@ExceptionHandler(value = {Exception.class})
public String getRuntimeException(){
return "error";
}
}