|
123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114 |
- # spring-boot-demo-actuator
-
- > 本 demo 主要演示了如何在 Spring Boot 中通过 actuator 检查项目运行情况
-
- ## pom.xml
-
- ```xml
- <?xml version="1.0" encoding="UTF-8"?>
- <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
- <modelVersion>4.0.0</modelVersion>
-
- <artifactId>spring-boot-demo-actuator</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- <packaging>jar</packaging>
-
- <name>spring-boot-demo-actuator</name>
- <description>Demo project for Spring Boot</description>
-
- <parent>
- <groupId>com.xkcoding</groupId>
- <artifactId>spring-boot-demo</artifactId>
- <version>1.0.0-SNAPSHOT</version>
- </parent>
-
- <properties>
- <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
- <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
- <java.version>1.8</java.version>
- </properties>
-
- <dependencies>
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-actuator</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-security</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-web</artifactId>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-starter-test</artifactId>
- <scope>test</scope>
- </dependency>
-
- <dependency>
- <groupId>org.springframework.security</groupId>
- <artifactId>spring-security-test</artifactId>
- <scope>test</scope>
- </dependency>
- </dependencies>
-
- <build>
- <finalName>spring-boot-demo-actuator</finalName>
- <plugins>
- <plugin>
- <groupId>org.springframework.boot</groupId>
- <artifactId>spring-boot-maven-plugin</artifactId>
- </plugin>
- </plugins>
- </build>
-
- </project>
- ```
-
- ## application.yml
-
- ```yaml
- server:
- port: 8080
- servlet:
- context-path: /demo
- # 若要访问端点信息,需要配置用户名和密码
- spring:
- security:
- user:
- name: xkcoding
- password: 123456
- management:
- # 端点信息接口使用的端口,为了和主系统接口使用的端口进行分离
- server:
- port: 8090
- servlet:
- context-path: /sys
- # 端点健康情况,默认值"never",设置为"always"可以显示硬盘使用情况和线程情况
- endpoint:
- health:
- show-details: always
- # 设置端点暴露的哪些内容,默认["health","info"],设置"*"代表暴露所有可访问的端点
- endpoints:
- web:
- exposure:
- include: '*'
- ```
-
- ## 端点暴露地址
-
- 将项目运行起来之后,会在**控制台**里查看所有可以访问的端口信息
- 1. 打开浏览器,访问:http://localhost:8090/sys/actuator/mappings ,输入用户名(xkcoding)密码(123456)即可看到所有的mapping信息
- 2. 访问:http://localhost:8090/sys/actuator/beans ,输入用户名(xkcoding)密码(123456)即可看到所有 Spring 管理的Bean
- 3. 其余可访问的路径,参见文档
-
- ## 参考
-
- - actuator文档:https://docs.spring.io/spring-boot/docs/2.0.5.RELEASE/reference/htmlsingle/#production-ready
- - 具体可以访问哪些路径,参考: https://docs.spring.io/spring-boot/docs/2.0.5.RELEASE/reference/htmlsingle/#production-ready-endpoints
|