You can not select more than 25 topics Topics must start with a chinese character,a letter or number, can include dashes ('-') and can be up to 35 characters long.

README.md 3.4 kB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. # spring-boot-demo-actuator
  2. > 本 demo 主要演示了如何在 Spring Boot 中通过 actuator 检查项目运行情况
  3. ## pom.xml
  4. ```xml
  5. <?xml version="1.0" encoding="UTF-8"?>
  6. <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  7. xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  8. <modelVersion>4.0.0</modelVersion>
  9. <artifactId>spring-boot-demo-actuator</artifactId>
  10. <version>1.0.0-SNAPSHOT</version>
  11. <packaging>jar</packaging>
  12. <name>spring-boot-demo-actuator</name>
  13. <description>Demo project for Spring Boot</description>
  14. <parent>
  15. <groupId>com.xkcoding</groupId>
  16. <artifactId>spring-boot-demo</artifactId>
  17. <version>1.0.0-SNAPSHOT</version>
  18. </parent>
  19. <properties>
  20. <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  21. <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
  22. <java.version>1.8</java.version>
  23. </properties>
  24. <dependencies>
  25. <dependency>
  26. <groupId>org.springframework.boot</groupId>
  27. <artifactId>spring-boot-starter-actuator</artifactId>
  28. </dependency>
  29. <dependency>
  30. <groupId>org.springframework.boot</groupId>
  31. <artifactId>spring-boot-starter-security</artifactId>
  32. </dependency>
  33. <dependency>
  34. <groupId>org.springframework.boot</groupId>
  35. <artifactId>spring-boot-starter-web</artifactId>
  36. </dependency>
  37. <dependency>
  38. <groupId>org.springframework.boot</groupId>
  39. <artifactId>spring-boot-starter-test</artifactId>
  40. <scope>test</scope>
  41. </dependency>
  42. <dependency>
  43. <groupId>org.springframework.security</groupId>
  44. <artifactId>spring-security-test</artifactId>
  45. <scope>test</scope>
  46. </dependency>
  47. </dependencies>
  48. <build>
  49. <finalName>spring-boot-demo-actuator</finalName>
  50. <plugins>
  51. <plugin>
  52. <groupId>org.springframework.boot</groupId>
  53. <artifactId>spring-boot-maven-plugin</artifactId>
  54. </plugin>
  55. </plugins>
  56. </build>
  57. </project>
  58. ```
  59. ## application.yml
  60. ```yaml
  61. server:
  62. port: 8080
  63. servlet:
  64. context-path: /demo
  65. # 若要访问端点信息,需要配置用户名和密码
  66. spring:
  67. security:
  68. user:
  69. name: xkcoding
  70. password: 123456
  71. management:
  72. # 端点信息接口使用的端口,为了和主系统接口使用的端口进行分离
  73. server:
  74. port: 8090
  75. servlet:
  76. context-path: /sys
  77. # 端点健康情况,默认值"never",设置为"always"可以显示硬盘使用情况和线程情况
  78. endpoint:
  79. health:
  80. show-details: always
  81. # 设置端点暴露的哪些内容,默认["health","info"],设置"*"代表暴露所有可访问的端点
  82. endpoints:
  83. web:
  84. exposure:
  85. include: '*'
  86. ```
  87. ## 端点暴露地址
  88. 将项目运行起来之后,会在**控制台**里查看所有可以访问的端口信息
  89. 1. 打开浏览器,访问:http://localhost:8090/sys/actuator/mappings ,输入用户名(xkcoding)密码(123456)即可看到所有的mapping信息
  90. 2. 访问:http://localhost:8090/sys/actuator/beans ,输入用户名(xkcoding)密码(123456)即可看到所有 Spring 管理的Bean
  91. 3. 其余可访问的路径,参见文档
  92. ## 参考
  93. - actuator文档:https://docs.spring.io/spring-boot/docs/2.0.5.RELEASE/reference/htmlsingle/#production-ready
  94. - 具体可以访问哪些路径,参考: https://docs.spring.io/spring-boot/docs/2.0.5.RELEASE/reference/htmlsingle/#production-ready-endpoints