在开发中我们修改一个 Java 文件后想看到效果不得不重启应用,这导致大量时间花费,我们希望不重启应用的情况下,程序可以自动部署(热部署)。
模板引擎
Spring Loaded
JRebel
Spring Boot Devtools
推荐使用
引入依赖
<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=mybeans
endpoints.shutdown.enabled=true
endpoints.beans.enabled=false
endpoints.enabled=false
endpoints.beans.enabled=true
定制端点访问根路径 management.context-path=/manage
关闭 http 端点 management.port=-1
自定义步骤:
编写一个指示器实现 HealthIndicator 接口
指示器的名字为 xxHealthIndicator
将其加入容器中
/**
@Component
public class MyAppHealthIndicator implements HealthIndicator {
@Override
public Health health() {
// 自定义检查方法
// Health.up().build() 代表健康
// Health.down().build() 代表不健康,还可以带上信息
return Health.down().withDetail("msg", "服务异常").build();
}
}
手机扫一扫
移动阅读更方便
你可能感兴趣的文章