w MimeMessageHelper(mimeMessage, true);
// 邮件发送方From和接收方To
helper.setFrom(userName);
helper.setTo(toUsers);
// 邮件主题和内容
helper.setSubject(subject);
helper.setText(content);
// 邮件中的附件
File attachFile = ResourceUtils.getFile(attachPath);
helper.addAttachment(attachFile.getName(), attachFile);
// 执行邮件发送命令
sender.send(mimeMessage);
return "send...mail...sus" ;
}
}
测试结果
六、应用监控
1、监控配置
在springboot
的actuator
组件中,可以通过提供的Rest
接口,来获取应用的监控信息;
# 应用监控配置
management:
endpoints:
web:
exposure:
# 打开所有的监控点
include: "*"
base-path: /monitor
endpoint:
health:
enabled: true
show-details: always
beans:
enabled: true
shutdown:
enabled: true
2、相关接口
2.1 Get类型接口:主机:端口/monitor/health
,查看应用的健康信息,三个核心指标:status
状态,diskSpace
磁盘空间,ping
检查;
{
/* 状态值 */
"status": "UP",
"components": {
/* 磁盘空间 */
"diskSpace": {
"status": "UP",
"details": {
"total": 250685575168,
"free": 112149811200,
"threshold": 10485760,
"path": "Path/butte-spring-parent/.",
"exists": true
}
},
/* Ping检查 */
"ping": {
"status": "UP"
}
}
}
2.2 Get类型接口:主机:端口/monitor/beans
,查看bean
列表;
{
"contexts": {
"boot-senior": {
"beans": {
"asyncPool": {
"scope": "singleton",
"type": "org.springframework.scheduling.concurrent.ThreadPoolTaskExecutor",
"resource": "class path resource [com/boot/senior/schedule/PoolConfig.class]"
},
"asyncService": {
"scope": "singleton",
"type": "com.boot.senior.schedule.AsyncService$$SpringCGLIB$$0"
}
}
}
}
}
2.3 Post类型接口:主机:端口/monitor/shutdown
,关闭应用程序;
{
"message": "Shutting down, bye..."
}
七、参考源码
文档仓库:
https://gitee.com/cicadasmile/butte-java-note
源码仓库:
https://gitee.com/cicadasmile/butte-spring-parent