Spring Boot学习笔记

89 阅读1分钟
  • 是什么,能做什么

基于spring的快速开发脚手架

  • spring boot 应用组成

  1. pom.xml 依赖文件,提供依赖管理和打包等功能
  2. 注解 @**** 通过注解完成自动配置
  3. 配置 application.properties/yml  提供配置参数和值
  4. static目录 静态文件
  5. templates目录 模板文件(JSP等)
  • 开发spring boot应用三板斧

  • 加依赖

通过pom.xml引入依赖包,依赖包规律如下:

boot官方提供的依赖  spring-boot-starter-xxxx

非官方提供 xxx-spring-boot-starter

官方starter查询  spring.io/projects/sp… 

  • 写注解

  • 写配置

  • Actuator spring boot应用监控


依赖

<dependency>    
    <groupId>org.springframework.boot</groupId>    
    <artifactId>spring-boot-starter-actuator</artifactId>
</dependency>

注解 无

配置 

management.endpoint.health.show-details=always
management.endpoints.web.exposure.include=*

常用端点

http://localhost:8080/actuator/health

{status: "UP",components: {diskSpace: {status: "UP",details: {total: 146800635904,free: 84896886784,threshold: 10485760,exists: true}},ping: {status: "UP"}}}

status: 

 UP 正常  

 DOWN 遇到问题,不正常 

 OUT_OF_SERVICE 资源未使用 

 UNKNOW 未知

http://localhost:8080/actuator/info

可以通过 info.xxx来配置,建议配置一些应用的描述信息。

http://localhost:8080/actuator/configprops

展示应用生效的配置属性

http://localhost:8080/actuator/metrics

监控指标

  • profile

yml中使用连字符区分

#公用配置属性

---

#profile=x的专用属性

---

#profile=y的专用属性