在开发中我们修改一个 Java 文件后想看到效果不得不重启应用,这导致大量时间花费,我们希望不重启应用的情况下,程序可以自动部署(热部署)。
推荐使用
引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<scope>runtime</scope>
<optional>true</optional>
</dependency>
按 CTRL+F9 生效
通过引入 spring-boot-starter-actuator,可以使用 Spring Boot 为我们提供的准生产环境下的应用监控和管理功能。我们可以通过HTTP,JMX,SSH协议来进行操作,自动得到审计、健康及指标信息等。
使用步骤:
引入依赖
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
通过 http 方式访问监控端点
可进行 shutdown(POST 提交,此端点默认关闭)
监控和管理端点说明:
autoconfig 所有自动配置信息auditevents 审计事件beans 所有 Bean 的信息configprops 所有配置属性dump 线程状态信息env 当前环境信息health 应用健康状况info 当前应用信息metrics 应用的各项指标mappings 应用 @RequestMapping 映射路径shutdown 关闭当前应用(默认关闭)trace 追踪信息(最新的 http 请求)endpoints+端点名+属性名 来设置,比如
endpoints.beans.id=mybeansendpoints.shutdown.enabled=trueendpoints.beans.enabled=falseendpoints.enabled=false endpoints.beans.enabled=truemanagement.context-path=/managemanagement.port=-1自定义步骤:
/**
* @Author : parzulpan
* @Time : 2021-01
* @Desc : 自定义健康指示器
*/
@Component
public class MyAppHealthIndicator implements HealthIndicator {
@Override
public Health health() {
// 自定义检查方法
// Health.up().build() 代表健康
// Health.down().build() 代表不健康,还可以带上信息
return Health.down().withDetail("msg", "服务异常").build();
}
}
【SpringBoot1.x】SpringBoot1.x 开发热部署和监控管理
原文:https://www.cnblogs.com/parzulpan/p/14226835.html