mirror of
https://gitee.com/yudaocode/SpringBoot-Labs.git
synced 2026-09-03 05:53:54 +08:00
增加 actuate demo 示例
This commit is contained in:
27
README.md
27
README.md
@@ -1,6 +1,17 @@
|
||||
艿艿 SpringBoot Lab 实验室。
|
||||
|
||||
# SpringBoot 入门
|
||||
# Spring Boot 专栏
|
||||
|
||||
基于 Spring Boot 2.X 版本的**深度**入门教程。
|
||||
|
||||
市面上的 Spring Boot **基础**入门文章很多,但是**深度**入门文章却很少。对于很多开发者来说,入门即是其对某个技术栈的最终理解,一方面是开发者“比较懒”,另一方面是文章作者把 Spring Boot 入门写的太浅,又或者不够全面。
|
||||
|
||||
因此,艿艿开始了这个 Spring Boot 专栏,一个**深度**且**全面**的 Spring Boot 2.X 入门。
|
||||
* 在带你快速学会 SpringMVC API 接口的编写的同时,我还想告诉你还有全局返回、全局异常、拦截器、跨域处理等等功能。
|
||||
* 在带你快速学会 MQ 消息的发送与消费的同时,我还想告诉你 MQ 还有集群消费、广播消费、顺序消息、定时消息、事务消息、消费重试等等特性。
|
||||
* 在带你快速学会 Job 任务的编写的同时,我还想告诉你还有 Quartz 单体、Quartz 集群、XXL-JOB 等等企业使用更多的调度平台。
|
||||
* ...
|
||||
|
||||
让我们一起愉快的挖坑,挖深坑,哇哈哈。
|
||||
|
||||
## Web 开发
|
||||
|
||||
@@ -53,7 +64,19 @@
|
||||
|
||||
## 监控管理
|
||||
|
||||
* [《芋道 Spring Boot 监控端点 Actuator 入门》](http://www.iocoder.cn/Spring-Boot/Actuator/?github) 对应 [lab-34](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-34) 。
|
||||
* [《芋道 Spring Boot 监控系统 Admin 入门》](http://www.iocoder.cn/Spring-Boot/Admin/?github) 对应 [lab-35](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-35) 。
|
||||
* [《芋道 Spring Boot 监控平台 Prometheus + Grafana 入门》](http://www.iocoder.cn/Spring-Boot/Prometheus-Grafana/?github) 对应 [lab-36](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-36) 。
|
||||
|
||||
## 日志管理
|
||||
|
||||
* Logger
|
||||
* ELK
|
||||
|
||||
## 链路追踪
|
||||
|
||||
* [《芋道 Spring Boot 链路追踪 SkyWalking 入门》](http://www.iocoder.cn/Spring-Boot/SkyWalking/?github) 对应 [lab-37](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-37) 。
|
||||
* [《芋道 Spring Boot 链路追踪 Zipkin 入门》](http://www.iocoder.cn/Spring-Boot/Zipkin/?github) 对应 [lab-38](https://github.com/YunaiV/SpringBoot-Labs/tree/master/lab-38) 。
|
||||
|
||||
## 性能测试
|
||||
|
||||
|
||||
35
lab-34/lab-34-actuator-demo-security/pom.xml
Normal file
35
lab-34/lab-34-actuator-demo-security/pom.xml
Normal file
@@ -0,0 +1,35 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-34-actuator-demo-security</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- 实现对 Spring MVC 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 Actuator 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 Spring Security 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-security</artifactId>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.iocoder.springboot.lab34.actuatordemo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class Application {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Application.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,20 @@
|
||||
package cn.iocoder.springboot.lab34.actuatordemo.config;
|
||||
|
||||
import org.springframework.boot.actuate.autoconfigure.security.servlet.EndpointRequest;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.security.config.annotation.web.builders.HttpSecurity;
|
||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter;
|
||||
|
||||
@Configuration
|
||||
public class SecurityConfig extends WebSecurityConfigurerAdapter {
|
||||
|
||||
@Override
|
||||
protected void configure(HttpSecurity http) throws Exception {
|
||||
// 访问 EndPoint 地址,需要经过认证,并且拥有 ADMIN 角色
|
||||
http.requestMatcher(EndpointRequest.toAnyEndpoint()).authorizeRequests((requests) ->
|
||||
requests.anyRequest().hasRole("ADMIN"));
|
||||
// 开启 Basic Auth
|
||||
http.httpBasic();
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,22 @@
|
||||
management:
|
||||
endpoints:
|
||||
# Actuator HTTP 配置项,对应 WebEndpointProperties 配置类
|
||||
web:
|
||||
base-path: /actuator # Actuator 提供的 API 接口的根目录。默认为 /actuator
|
||||
exposure:
|
||||
include: '*' # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 * ,可以开放所有端点。
|
||||
exclude: # 在 include 的基础上,需要排除的端点。通过设置 * ,可以排除所有端点。
|
||||
# server:
|
||||
# port: 8081
|
||||
# endpoint:
|
||||
# shutdown:
|
||||
# enabled: true
|
||||
|
||||
spring:
|
||||
# Spring Security 配置项,对应 SecurityProperties 配置类
|
||||
security:
|
||||
# 配置默认的 InMemoryUserDetailsManager 的用户账号与密码。
|
||||
user:
|
||||
name: user # 账号
|
||||
password: user # 密码
|
||||
roles: ADMIN # 拥有角色
|
||||
@@ -0,0 +1,22 @@
|
||||
management:
|
||||
endpoints:
|
||||
# Actuator HTTP 配置项,对应 WebEndpointProperties 配置类
|
||||
web:
|
||||
base-path: /actuator # Actuator 提供的 API 接口的根目录。默认为 /actuator
|
||||
exposure:
|
||||
include: '*' # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 * ,可以开放所有端点。
|
||||
exclude: # 在 include 的基础上,需要排除的端点。通过设置 * ,可以排除所有端点。
|
||||
# server:
|
||||
# port: 8081
|
||||
# endpoint:
|
||||
# shutdown:
|
||||
# enabled: true
|
||||
|
||||
spring:
|
||||
# Spring Security 配置项,对应 SecurityProperties 配置类
|
||||
security:
|
||||
# 配置默认的 InMemoryUserDetailsManager 的用户账号与密码。
|
||||
user:
|
||||
name: user # 账号
|
||||
password: user # 密码
|
||||
roles: ADMIN # 拥有角色
|
||||
@@ -6,6 +6,8 @@ management:
|
||||
exposure:
|
||||
include: '*' # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 * ,可以开放所有端点。
|
||||
exclude: # 在 include 的基础上,需要排除的端点。通过设置 * ,可以排除所有端点。
|
||||
# server:
|
||||
# port: 8081
|
||||
# endpoint:
|
||||
# shutdown:
|
||||
# enabled: true
|
||||
|
||||
@@ -19,6 +19,7 @@
|
||||
<module>lab-34-actuator-demo-httptrace</module>
|
||||
<module>lab-34-actuator-demo-auditevents</module>
|
||||
<module>lab-34-actuator-demo-custom-endpoint</module>
|
||||
<module>lab-34-actuator-demo-security</module>
|
||||
</modules>
|
||||
|
||||
|
||||
|
||||
29
lab-35/lab-35-admin-01-adminserver/pom.xml
Normal file
29
lab-35/lab-35-admin-01-adminserver/pom.xml
Normal file
@@ -0,0 +1,29 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-35-admin-01-adminserver</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- 实现对 Spring Boot Admin Server 的自动化配置 -->
|
||||
<!--
|
||||
包含 1. spring-boot-admin-server :Server 端
|
||||
2. spring-boot-admin-server-ui :UI 界面
|
||||
3. spring-boot-admin-server-cloud :对 Spring Cloud 的接入
|
||||
-->
|
||||
<dependency>
|
||||
<groupId>de.codecentric</groupId>
|
||||
<artifactId>spring-boot-admin-starter-server</artifactId>
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,15 @@
|
||||
package cn.iocoder.springboot.lab35.adminserver;
|
||||
|
||||
import de.codecentric.boot.admin.server.config.EnableAdminServer;
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
@EnableAdminServer
|
||||
public class AdminServerApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(AdminServerApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
36
lab-35/lab-35-admin-01-demo-application/pom.xml
Normal file
36
lab-35/lab-35-admin-01-demo-application/pom.xml
Normal file
@@ -0,0 +1,36 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-parent</artifactId>
|
||||
<version>2.2.2.RELEASE</version>
|
||||
<relativePath/> <!-- lookup parent from repository -->
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-35-admin-01-demo-application</artifactId>
|
||||
|
||||
<dependencies>
|
||||
<!-- 实现对 Spring MVC 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-web</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 Actuator 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>org.springframework.boot</groupId>
|
||||
<artifactId>spring-boot-starter-actuator</artifactId>
|
||||
</dependency>
|
||||
|
||||
<!-- 实现对 Spring Boot Admin Client 的自动化配置 -->
|
||||
<dependency>
|
||||
<groupId>de.codecentric</groupId>
|
||||
<artifactId>spring-boot-admin-starter-client</artifactId>
|
||||
<version>2.2.0</version>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
</project>
|
||||
@@ -0,0 +1,13 @@
|
||||
package cn.iocoder.springboot.lab34.actuatordemo;
|
||||
|
||||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
|
||||
@SpringBootApplication
|
||||
public class DemoApplication {
|
||||
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(DemoApplication.class, args);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,17 @@
|
||||
management:
|
||||
endpoints:
|
||||
# Actuator HTTP 配置项,对应 WebEndpointProperties 配置类
|
||||
web:
|
||||
exposure:
|
||||
include: '*' # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 * ,可以开放所有端点。
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: demo-application # 应用名
|
||||
boot:
|
||||
admin:
|
||||
client:
|
||||
url: http://127.0.0.1:8080 # Spring Boot Admin Server 地址
|
||||
|
||||
server:
|
||||
port: 18080 # 设置自定义 Server 端口,避免和 Spring Boot Admin Server 端口冲突。
|
||||
@@ -0,0 +1,17 @@
|
||||
management:
|
||||
endpoints:
|
||||
# Actuator HTTP 配置项,对应 WebEndpointProperties 配置类
|
||||
web:
|
||||
exposure:
|
||||
include: '*' # 需要开放的端点。默认值只打开 health 和 info 两个端点。通过设置 * ,可以开放所有端点。
|
||||
|
||||
spring:
|
||||
application:
|
||||
name: demo-application # 应用名
|
||||
boot:
|
||||
admin:
|
||||
client:
|
||||
url: http://127.0.0.1:8080 # Spring Boot Admin Server 地址
|
||||
|
||||
server:
|
||||
port: 18080 # 设置自定义 Server 端口,避免和 Spring Boot Admin Server 端口冲突。
|
||||
20
lab-35/pom.xml
Normal file
20
lab-35/pom.xml
Normal file
@@ -0,0 +1,20 @@
|
||||
<?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">
|
||||
<parent>
|
||||
<artifactId>labs-parent</artifactId>
|
||||
<groupId>cn.iocoder.springboot.labs</groupId>
|
||||
<version>1.0-SNAPSHOT</version>
|
||||
</parent>
|
||||
<modelVersion>4.0.0</modelVersion>
|
||||
|
||||
<artifactId>lab-35</artifactId>
|
||||
<packaging>pom</packaging>
|
||||
<modules>
|
||||
<module>lab-35-admin-01-adminserver</module>
|
||||
<module>lab-35-admin-01-demo-application</module>
|
||||
</modules>
|
||||
|
||||
|
||||
</project>
|
||||
Reference in New Issue
Block a user