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