最近在学习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:生产环境配置文件
然后这样就实现了多环境配置的功能,在项目中根据不能的环境进行开发,部署。
加入群聊一起学习交流: