diff --git a/spring-boot-demo-actuator/.gitignore b/spring-boot-demo-actuator/.gitignore new file mode 100644 index 0000000..82eca33 --- /dev/null +++ b/spring-boot-demo-actuator/.gitignore @@ -0,0 +1,25 @@ +/target/ +!.mvn/wrapper/maven-wrapper.jar + +### STS ### +.apt_generated +.classpath +.factorypath +.project +.settings +.springBeans +.sts4-cache + +### IntelliJ IDEA ### +.idea +*.iws +*.iml +*.ipr + +### NetBeans ### +/nbproject/private/ +/build/ +/nbbuild/ +/dist/ +/nbdist/ +/.nb-gradle/ \ No newline at end of file diff --git a/spring-boot-demo-actuator/README.md b/spring-boot-demo-actuator/README.md new file mode 100644 index 0000000..0f2ae1e --- /dev/null +++ b/spring-boot-demo-actuator/README.md @@ -0,0 +1,109 @@ +# spring-boot-demo-actuator + +> 本 demo 主要演示了如何在 Spring Boot 中通过 actuator 检查项目运行情况 + +## pom.xml + +```xml + + + 4.0.0 + + com.xkcoding + spring-boot-demo-actuator + 0.0.1-SNAPSHOT + jar + + spring-boot-demo-actuator + Demo project for Spring Boot + + + org.springframework.boot + spring-boot-starter-parent + 2.0.5.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + + spring-boot-demo-actuator + + + org.springframework.boot + spring-boot-maven-plugin + + + + + +``` + +## 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: '*' +``` + +## 端点暴露地址 + +将项目运行起来之后,会在**控制台**里查看所有可以访问的端口信息 + +## 参考 + +https://docs.spring.io/spring-boot/docs/2.0.5.RELEASE/reference/htmlsingle/#production-ready \ No newline at end of file diff --git a/spring-boot-demo-actuator/pom.xml b/spring-boot-demo-actuator/pom.xml new file mode 100644 index 0000000..78c4eee --- /dev/null +++ b/spring-boot-demo-actuator/pom.xml @@ -0,0 +1,63 @@ + + + 4.0.0 + + com.xkcoding + spring-boot-demo-actuator + 0.0.1-SNAPSHOT + jar + + spring-boot-demo-actuator + Demo project for Spring Boot + + + org.springframework.boot + spring-boot-starter-parent + 2.0.5.RELEASE + + + + + UTF-8 + UTF-8 + 1.8 + + + + + org.springframework.boot + spring-boot-starter-actuator + + + org.springframework.boot + spring-boot-starter-security + + + org.springframework.boot + spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-test + test + + + org.springframework.security + spring-security-test + test + + + + + spring-boot-demo-actuator + + + org.springframework.boot + spring-boot-maven-plugin + + + + + diff --git a/spring-boot-demo-actuator/src/main/java/com/xkcoding/actuator/SpringBootDemoActuatorApplication.java b/spring-boot-demo-actuator/src/main/java/com/xkcoding/actuator/SpringBootDemoActuatorApplication.java new file mode 100644 index 0000000..6774035 --- /dev/null +++ b/spring-boot-demo-actuator/src/main/java/com/xkcoding/actuator/SpringBootDemoActuatorApplication.java @@ -0,0 +1,25 @@ +package com.xkcoding.actuator; + +import org.springframework.boot.SpringApplication; +import org.springframework.boot.autoconfigure.SpringBootApplication; + +/** + *

+ * 启动类 + *

+ * + * @package: com.xkcoding.actuator + * @description: 启动类 + * @author: yangkai.shen + * @date: Created in 2018/9/29 2:27 PM + * @copyright: Copyright (c)2018 + * @version: V1.0 + * @modified: yangkai.shen + */ +@SpringBootApplication +public class SpringBootDemoActuatorApplication { + + public static void main(String[] args) { + SpringApplication.run(SpringBootDemoActuatorApplication.class, args); + } +} diff --git a/spring-boot-demo-actuator/src/main/resources/application.yml b/spring-boot-demo-actuator/src/main/resources/application.yml new file mode 100644 index 0000000..d1dbefe --- /dev/null +++ b/spring-boot-demo-actuator/src/main/resources/application.yml @@ -0,0 +1,25 @@ +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: '*' \ No newline at end of file diff --git a/spring-boot-demo-actuator/src/test/java/com/xkcoding/actuator/SpringBootDemoActuatorApplicationTests.java b/spring-boot-demo-actuator/src/test/java/com/xkcoding/actuator/SpringBootDemoActuatorApplicationTests.java new file mode 100644 index 0000000..4416b96 --- /dev/null +++ b/spring-boot-demo-actuator/src/test/java/com/xkcoding/actuator/SpringBootDemoActuatorApplicationTests.java @@ -0,0 +1,16 @@ +package com.xkcoding.actuator; + +import org.junit.Test; +import org.junit.runner.RunWith; +import org.springframework.boot.test.context.SpringBootTest; +import org.springframework.test.context.junit4.SpringRunner; + +@RunWith(SpringRunner.class) +@SpringBootTest +public class SpringBootDemoActuatorApplicationTests { + + @Test + public void contextLoads() { + } + +}