Spring Boot学习二 多环境配置

最近在学习Spring Boot 因为虽然在工作中使用过这个技术,但是并没有多少的时间去了解过他,更没有系统的去学习过这门技术,只是说简单的去使用了,所以这段时间我就在研究他,首先我们来看看Spring Boot的一个监控组件:

Spring boot Actuator

Spring Boot 监控与管理,这个主要是用来监控项目的一些资源,配置,和一些项目的详细资料:比如我们需要查看当前项目的jvm 参数
tomact等一些配置参数,或者想查看配置有没有生效等

加入项目依赖:

org.springframework.boot
spring-boot-starter-actuator

然后启动tomact 访问
http://localhost:8080/actuator
如果看不到东西那么就在配置文件中加入配置:
management.endpoint.health.show-details=always

#激活所有的actuator端点
management.endpoints.web.exposure.include=*
然后就会看到监控的一些路径,自己访问一下就好
http://localhost:8080/actuator/configprops" 查看项目的配置环境
其他的自己看官方文档:
https://docs.spring.io/spring-boot/docs/current/actuator-api/html/#overview

Spring Boot 多环境配置: Profile
如果我们的项目配置文件是 yml文件的话那就使用
— 隔开 来表示不能的环境

#默认环境
management:
  endpoint:
    health:
      show-details: always
  endpoints:
    web:
      exposure:
        include: '*'
#默认以dev的环境启动
spring:
  profiles:
    active: dev
---
#开发环境 dev
spring:
  profiles: dev
---
#生产环境
spring:
  profiles: prod
server:
  tomcat:
    max-threads: 300
    max-connections: 1000

如果我们是使用.properties 启动项目,那就在文件加上名字做区分:
application-properties:公共的配置文件

spring.profiles.active=prod 指定使用哪个环境的配置文件启动做项目依赖

application-dev-properties:开发环境配置文件

application-prod-properties:生产环境配置文件

然后这样就实现了多环境配置的功能,在项目中根据不能的环境进行开发,部署。
加入群聊一起学习交流:
在这里插入图片描述

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值