SpringBoot 自定义starter -- 解决异常通知
SpringBoot的确简单,基本都是自动配置 通过自定义starter 了解自动配置
需求:线上代码500了 怎么及时通知到位
解决:自定义starter,通过 org.springframework.web.servlet.HandlerExceptionResolver 来监听异常,然后异步邮件推送
对于自定义starter命名 Spring官方约定 {name}-spring-boot-starter
关于SpringBoot启动自己加载配置 可以看这篇博客 挺不错的 https://blog.****.net/u014745069/article/details/83820511
源码地址: https://gitee.com/love_yu_0698/exception-mail-spring-boot-starter.git
项目结构
然后打成jar包,引入其他项目one
Ps:启动项目one 测试异常 出现问题,mail包中的一个类找不到,
mail包是在自定义starter中引入的,但是再新项目中没有带进来
(目前解决方案:1、项目one 新增mail依赖 2、将jar包上传至maven私服)
通过debug 自定义starter的代码是运行了,但是不是异步的,如果需要异步发送 ,需要在启动类 加上注解 @EnableAsync