异常捕获注解 全局捕获
@ControllerAdvice
public class CatchGlobalExcepction {
@ExceptionHandler(value = Exception.class)
public void toDispose(HttpServletRequest req ,Exception e){
System.out.println("tttttttttttt");
e.printStackTrace();
}
}
@Controller
@EnableAutoConfiguration
@SpringBootApplication(scanBasePackages = {"com.xz","com.xz.base.exception"}) //目的为了让spring扫描到这个类 不然违法捕获异常
public class HellowSpringBoot {
@RequestMapping("/hsb")
@ResponseBody
public String hellow(){
int a = 100/0;//制造异常
return "hellowSpringBoot的点点滴滴";
}
public static void main(String[] args) {
SpringApplication.run(HellowSpringBoot.class, args);
}
}