Skip to content

Commit 971a349

Browse files
committed
✨ spring-boot-demo-actuator 完成
1 parent f419077 commit 971a349

File tree

6 files changed

+263
-0
lines changed

6 files changed

+263
-0
lines changed

spring-boot-demo-actuator/.gitignore

+25
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
/target/
2+
!.mvn/wrapper/maven-wrapper.jar
3+
4+
### STS ###
5+
.apt_generated
6+
.classpath
7+
.factorypath
8+
.project
9+
.settings
10+
.springBeans
11+
.sts4-cache
12+
13+
### IntelliJ IDEA ###
14+
.idea
15+
*.iws
16+
*.iml
17+
*.ipr
18+
19+
### NetBeans ###
20+
/nbproject/private/
21+
/build/
22+
/nbbuild/
23+
/dist/
24+
/nbdist/
25+
/.nb-gradle/

spring-boot-demo-actuator/README.md

+109
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
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

spring-boot-demo-actuator/pom.xml

+63
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
3+
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
4+
<modelVersion>4.0.0</modelVersion>
5+
6+
<groupId>com.xkcoding</groupId>
7+
<artifactId>spring-boot-demo-actuator</artifactId>
8+
<version>0.0.1-SNAPSHOT</version>
9+
<packaging>jar</packaging>
10+
11+
<name>spring-boot-demo-actuator</name>
12+
<description>Demo project for Spring Boot</description>
13+
14+
<parent>
15+
<groupId>org.springframework.boot</groupId>
16+
<artifactId>spring-boot-starter-parent</artifactId>
17+
<version>2.0.5.RELEASE</version>
18+
<relativePath/> <!-- lookup parent from repository -->
19+
</parent>
20+
21+
<properties>
22+
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
23+
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
24+
<java.version>1.8</java.version>
25+
</properties>
26+
27+
<dependencies>
28+
<dependency>
29+
<groupId>org.springframework.boot</groupId>
30+
<artifactId>spring-boot-starter-actuator</artifactId>
31+
</dependency>
32+
<dependency>
33+
<groupId>org.springframework.boot</groupId>
34+
<artifactId>spring-boot-starter-security</artifactId>
35+
</dependency>
36+
<dependency>
37+
<groupId>org.springframework.boot</groupId>
38+
<artifactId>spring-boot-starter-web</artifactId>
39+
</dependency>
40+
41+
<dependency>
42+
<groupId>org.springframework.boot</groupId>
43+
<artifactId>spring-boot-starter-test</artifactId>
44+
<scope>test</scope>
45+
</dependency>
46+
<dependency>
47+
<groupId>org.springframework.security</groupId>
48+
<artifactId>spring-security-test</artifactId>
49+
<scope>test</scope>
50+
</dependency>
51+
</dependencies>
52+
53+
<build>
54+
<finalName>spring-boot-demo-actuator</finalName>
55+
<plugins>
56+
<plugin>
57+
<groupId>org.springframework.boot</groupId>
58+
<artifactId>spring-boot-maven-plugin</artifactId>
59+
</plugin>
60+
</plugins>
61+
</build>
62+
63+
</project>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package com.xkcoding.actuator;
2+
3+
import org.springframework.boot.SpringApplication;
4+
import org.springframework.boot.autoconfigure.SpringBootApplication;
5+
6+
/**
7+
* <p>
8+
* 启动类
9+
* </p>
10+
*
11+
* @package: com.xkcoding.actuator
12+
* @description: 启动类
13+
* @author: yangkai.shen
14+
* @date: Created in 2018/9/29 2:27 PM
15+
* @copyright: Copyright (c)2018
16+
* @version: V1.0
17+
* @modified: yangkai.shen
18+
*/
19+
@SpringBootApplication
20+
public class SpringBootDemoActuatorApplication {
21+
22+
public static void main(String[] args) {
23+
SpringApplication.run(SpringBootDemoActuatorApplication.class, args);
24+
}
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
server:
2+
port: 8080
3+
servlet:
4+
context-path: /demo
5+
# 若要访问端点信息,需要配置用户名和密码
6+
spring:
7+
security:
8+
user:
9+
name: xkcoding
10+
password: 123456
11+
management:
12+
# 端点信息接口使用的端口,为了和主系统接口使用的端口进行分离
13+
server:
14+
port: 8090
15+
servlet:
16+
context-path: /sys
17+
# 端点健康情况,默认值"never",设置为"always"可以显示硬盘使用情况和线程情况
18+
endpoint:
19+
health:
20+
show-details: always
21+
# 设置端点暴露的哪些内容,默认["health","info"],设置"*"代表暴露所有可访问的端点
22+
endpoints:
23+
web:
24+
exposure:
25+
include: '*'
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
package com.xkcoding.actuator;
2+
3+
import org.junit.Test;
4+
import org.junit.runner.RunWith;
5+
import org.springframework.boot.test.context.SpringBootTest;
6+
import org.springframework.test.context.junit4.SpringRunner;
7+
8+
@RunWith(SpringRunner.class)
9+
@SpringBootTest
10+
public class SpringBootDemoActuatorApplicationTests {
11+
12+
@Test
13+
public void contextLoads() {
14+
}
15+
16+
}

0 commit comments

Comments
 (0)