Spring Boot 增强----(多环境配置 , actuator监控 , 热部署)
1.1创建父项目
步骤一:创建父项目 cloud_parent
步骤二:修改 cloud_parent 父项目中的 pom.xml文件,确定spring boot版本
<!--确定spring boot的版本-->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>2.1.4.RELEASE</version>
</parent>
1.2 profiles多环境配置
在开发中,项目会被部署到不同的运行环境中,如:测试环境、生产环境。Spring boot 允许配置多个yml文件(application-环境名.properties),并通过 spring.profiles.active=环境 来激活不同的环境。
步骤一:
1.在 cloud_parent父项目 下创建 profiles_demo项目
2.在profiles_demo项目的 pom.xml文件中配置web启动器
<!--web起步依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
3.创建profiles_demo项目的启动类
步骤二:创建多个yml文件
步骤三:在application.yml文件中,确定激活那个配置文件
1.3 actuator监控
Spring boot 提供了一个用于监控和管理自身应用信息的模块:spring-boot-starter-actuator 添加依赖就可以直接使用。
<!--监控依赖-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
访问路径: http://localhost:9096/actuator
访问结果:
1.4 热部署
热部署:代码修改后,刷新浏览器会自动重启服务器,重启完毕再次刷新浏览器就可以看到效果
步骤一:修改pom.xml添加 spring-boot-devtools依赖
<!--热部署-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-devtools</artifactId>
</dependency>
步骤二:开启IDEA自动编译
步骤三: 在 pom.xml 中 快捷键Shift+Ctrl+Alt+/,选择Registry,将“compiler.auto....app.running”勾选