一.热部署java
在开发中咱们修改一个Java文件后想看到效果不得不重启应用,这致使大量时间花费,咱们不但愿重启应用的状况下,程序能够自动部署(热部署)。git
1.1 模板引擎github
在SpringBoot中开发状况下禁用模板引擎的cache,页面模板改变ctrl+F9能够从新编译当前页面并生效。redis
1.2 Spring Loadedspring
Spring官方提供的热部署程序,实现修改类文件的热部署,须要下载Spring Loaded(项目地址),使用时须要添加运行时参数:-javaagent:C:/springloaded-1.2.5.RELEASE.jar-noverifyeclipse
1.3 JRebelide
收费的一个热部署软件,安装插件使用。spring-boot
1.4 Spring Boot Devtools(推荐)post
引入依赖,使用IDEA的编译或者ctrl+f9,若是用eclipse使用保存即ctrl+s便可实现热部署。ui
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
<optional>true</optional>
</dependency>
二.监控管理
经过引入spring-boot-starter-actuator,可使用Spring Boot为咱们提供的准生产环境下的应用监控和管理功能。咱们能够经过HTTP、JMX,SSH协议来进行操做,自动获得审计、健康及指标信息等。
因为SpringBoot2.x版本在这一块有所变更因此须要将SpringBoot版本切换为1.5.x版本,防止版本问题影响。
2.1 引入spring-boot-starter-actuator
<dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency>
2.2 经过http方式访问监控端点
监控和管理端点:
2.3 可进行shutdown(POST提交,此端点默认关闭)
能够经过发送"/shutdown"post请求来关闭应用。
2.3.1 开启shutdown关闭应用
endpoints.shutdown.enabled=true
2.3.2 使用postman发送post请求
2.4 定制端点信息
定制端点通常经过endpoints+端点名+属性名来设置。
修改端点id(endpoints.beans.id=mybeans),这样设置之后访问beans端点就须要访问"/mybeans"了
修改端点访问路径(endpoints.beans.path=beans)
开启远程应用关闭功能(endpoints.shutdown.enabled=true)
开启关闭端点(endpoints.beans.enabled=false)
关闭全部端点访问(endpoints.enabled=false)
修改根路径方法(management.context-path=/manage)
修改访问端点的端口(management.port=8181)
2.5 自定义HealthIndicator
访问/health端口,能够看到应用监控的监控情况。例如redis链接是否正常,若是链接地址不正确致使链接不上redis地址,健康状态就会显示down。那么如何自定义一个健康状态指示器呢?
首先,编写一个指示器 实现HealthIndicator接口,而且指示器的名字须要命名为xxxHealthIndicator并加入容器中。
@Component public class MyHealthIndicator implements HealthIndicator { @Override public Health health() { //自定义检查方法 // return Health.up().build(); return Health.down().withDetail("msg","服务异常").build(); } }
所有编写好后,重启项目访问"/health"就能够查看该指示器了。