Author | SHA1 | Message | Date |
---|---|---|---|
|
eaea6126d4 | 🎉 init multilevel cache. | 2 years ago |
|
4fc806b614 | 🏗️ 规范配置 | 2 years ago |
|
09910e7088 | 🎉 init multilevel cache. | 2 years ago |
|
d6f4964a47 | 🎨 规范 pom 文件格式 | 2 years ago |
|
19548b4429 | 💥 移除 spring.factories, 自动装配方式调整 | 2 years ago |
|
13f9c8b765 | ✨ 其他模块之读写分离案例完成 | 2 years ago |
|
2b644f759c | ⬆️ 升级 Spring Boot 版本为 3.0.0-M5 | 2 years ago |
|
0e86607ef6 | 🎨 规范 README 文件格式 | 2 years ago |
|
27f7bef621 | ✨ 基础模块之 文件上传 案例完成 | 2 years ago |
|
4d0391f034 | ✨ 定时任务模块之 SpringTask 案例完成 | 2 years ago |
|
721f6b0646 | ✨ 缓存模块之 caffeine 缓存案例完成 | 2 years ago |
|
c36fb10ef8 | ✨ 缓存模块之 ehcache 缓存案例完成 | 2 years ago |
|
9b7b7e04b6 | 🎨 规范 README 文件格式 | 2 years ago |
|
fee87d959b | 📝 更新缓存模块 redis 缓存 案例的 README 文件 | 2 years ago |
|
bbb3f3a98e | ✨ 缓存模块之 redis 缓存案例完成 | 2 years ago |
|
5751436a69 | ✨ API文档模块之 springdoc 案例完成 | 2 years ago |
|
369421e97c | 🏗️ 规范模块 | 2 years ago |
|
b93f5430c8 | 🔥 移除低优先级模块 | 2 years ago |
|
db1c76e259 | 📝 更新日志模块 graylog 案例的 README 文件 | 2 years ago |
|
198ba0bd8c | ✨ 日志模块之 graylog 案例完成 | 2 years ago |
|
2510c60e56 | 🎨 规范模块名称 | 2 years ago |
|
c2129fb2a5 | 🚧 初始化分布式锁模块之基于 MySQL 实现分布式锁案例 | 2 years ago |
|
b3fe0c3cbb | 🎨 规范 pom 文件格式 | 2 years ago |
|
ac3e5ac5c6 | ✨ 分布式锁模块之 基于 Zookeeper原生客户端 实现分布式锁 案例完成 | 2 years ago |
|
17e3aacfd1 | 🎨 规范 pom 文件格式 | 2 years ago |
|
3dc49e42e4 | 📝 更新 RedisTemplate 分布式锁模块的 README 文件 | 2 years ago |
|
7ef8153d6f | 📝 更新 Curator 分布式锁模块的 README 文件 | 2 years ago |
|
0b7ba41562 | 📌 升级 curator 里的 zookeeper 版本为 3.8.0 | 2 years ago |
|
aefab0b2fd | 📝 更新 RedisTemplate 分布式锁模块的 README 文件 | 2 years ago |
|
a6c1902593 | ✨ 分布式锁模块之 基于 RedisTemplate 实现分布式锁 案例完成 | 2 years ago |
|
fefce29cb1 | 🐛 修改默认加锁单位为毫秒 | 2 years ago |
|
f980ce8b0c | 🔥 移除改造完成的模块 | 2 years ago |
|
e6f741ebb4 | 🎨 规范 pom 文件格式 | 2 years ago |
|
41160df3d5 | ✨ 分布式锁模块之 基于 curator 实现分布式锁 案例完成 | 2 years ago |
|
e8c052a069 | 💡 完善注释 | 2 years ago |
|
22389b1f0c | 📝 更新 Redisson 分布式锁模块的 README 文件 | 2 years ago |
|
3227e1d191 | 📝 更新 Redisson 分布式锁模块的 README 文件 | 2 years ago |
|
f788382138 | 📝 更新 Redisson 分布式锁模块的 README 文件,同时新增一键环境搭建脚本 | 2 years ago |
|
7d9fdbe76a | ✨ 分布式锁模块之 基于 redisson 实现分布式锁 案例完成 | 2 years ago |
|
721dabf2b4 | ♻️ 移除冗余代码 && 增加快速失败 | 2 years ago |
|
05e0d33c3c | ♻️ 修改类名,见名知意 | 2 years ago |
|
52b288f1d4 | 🐛 修复 spring boot 3.x 配合 mybatis-plus 启动失败问题 | 2 years ago |
|
86fc5e27f2 | ✨ 实现分布式锁接口、AOP拦截、自动装配模块,默认为虚拟加锁,具体实现参考其他模块 | 2 years ago |
|
d9428a8b77 | 🎨 通用依赖版本统一管理 | 2 years ago |
|
f60a04259d | 💡 修改注释 | 2 years ago |
|
8ceeb0e057 | 🏗️ 新增分布式锁模块 | 2 years ago |
|
38b9d0c3ea | 📝 更新 README 感谢 | 2 years ago |
|
63990bf3cb | ♻️ 修改模块名称 | 2 years ago |
|
b0f5a88151 | ✨ 日志模块之 aop日志拦截 案例完成 | 2 years ago |
|
712d5e23cf | 📝 更新 docker 模块的 README 文件 | 2 years ago |
|
f8d8e27b4e | 📝 更新 war 模块的 README 文件 | 2 years ago |
|
768a5c193e | 📝 更新 logback 模块的 README 文件 | 2 years ago |
|
7701ac3992 | 📝 更新 异步任务 模块的 README 文件 | 2 years ago |
|
4f061da57b | 📝 更新 邮件 模块的 README 文件 | 2 years ago |
|
45c2758d21 | 📝 更新 https 模块的 README 文件 | 2 years ago |
|
03b2793d07 | ✨ 日志模块之 logback 案例完成 | 2 years ago |
|
8cd4a9196a | 📝 remove ad | 2 years ago |
|
83eba99151 | ✨ 打包模块之 war 案例完成 | 2 years ago |
|
c5d3c76b39 | ✨ 打包模块之 war 案例完成 | 2 years ago |
|
d539ebe0c4 | ✨ 基础模块之 邮件 案例完成 | 2 years ago |
|
e9135d16e8 | ✨ 打包模块之 docker 案例完成 | 2 years ago |
|
6f8d28dca8 | ✨ 打包模块之 docker 案例完成 | 2 years ago |
|
0ace6bfd9c | ✨ 基础模块之 邮件 案例完成 | 2 years ago |
|
b3ccfdf2a9 | 📝 更新 https 模块的 README 文件 | 2 years ago |
|
a08bc5fd51 | ✨ 其他模块之 https 案例完成 | 2 years ago |
|
e22505a956 | 📝 更新 actuator 模块的 README 文件 | 2 years ago |
|
6ab7e297d3 | 📝 更新 异步任务 模块的 README 文件 | 2 years ago |
|
4d1ddaa568 | 📝 更新 properties 模块的 README 文件 | 2 years ago |
|
5166f939c8 | 📝 更新 helloworld 模块的 README 文件 | 2 years ago |
|
29c5e48420 | 👷 更新 CI 流程 | 2 years ago |
|
73c54ea862 | ✨ 基础模块之 统一异常拦截 案例完成 | 2 years ago |
|
2da4a16172 | ♻️ 初始化通用类 | 2 years ago |
|
b5a81397b0 | 👷 更新 CI 流程 | 2 years ago |
|
421dc20fdc | 👷 更新 CI 流程 | 2 years ago |
|
66ba2153a7 | 👷 更新 CI 流程 | 2 years ago |
|
19a2b543b9 | 👷 更新 CI 流程 | 2 years ago |
|
bdb53ae064 | 👷 更新 CI 流程 | 2 years ago |
|
7124e0f2c5 | 👷 更新 CI 流程 | 2 years ago |
|
d8d3b3dc40 | 👷 更新 CI 流程 | 2 years ago |
|
3e846d2b40 | 👷 更新 CI 流程 | 2 years ago |
|
0cf53435b2 | 👷 更新 CI 流程 | 2 years ago |
|
b267e39e6a | 👷 更新 CI 流程 | 2 years ago |
|
83d09ac41d | 👷 更新 CI 流程 | 2 years ago |
|
1dd746b599 | 👷 更新 CI 流程 | 2 years ago |
|
9a88f39db9 | 👷 更新 CI 流程 | 2 years ago |
|
f0103a8784 | 👷 更新 CI 流程 | 2 years ago |
|
7e63c7ea57 | 👷 更新 CI 流程 | 2 years ago |
|
8fe0ce493b | 👷 更新 CI 流程 | 2 years ago |
|
2702caaeff | 👷 更新 CI 流程 | 2 years ago |
|
ab33bd0f3a | 👷 更新 CI 流程 | 2 years ago |
|
650e792dfb | ✨ 基础模块之 异步任务 案例完成 | 2 years ago |
|
284482e0f1 | 📝 更新 admin 模块的 README 文件 | 2 years ago |
|
72054110bf | 👷 更新 CI 流程 | 2 years ago |
|
e39a854958 | 🏗️ 新增其他模块 | 2 years ago |
|
95e180eaff | 🏗️ 新增打包部署模块 | 2 years ago |
|
c07b1efc3e | 🏗️ 新增工作流模块 | 2 years ago |
|
fd0a2445a4 | 🏗️ 新增幂等模块 | 2 years ago |
|
22fe68f816 | 🏗️ 新增流量控制模块 | 2 years ago |
|
71cc1254e9 | 🏗️ 新增API文档模块 | 2 years ago |
|
c61339166e | 🏗️ 新增安全认证模块 | 2 years ago |
|
04475cc1e9 | 🏗️ 新增websocket模块 | 2 years ago |
|
4844bd4ea8 | 🎨 规范格式化 pom 文件 | 2 years ago |
|
c8445c382f | 🏗️ 新增消息队列模块 | 2 years ago |
|
125aa85202 | 🏗️ 新增定时任务模块 | 2 years ago |
|
0c77331c6b | 🏗️ 新增mq模块 | 2 years ago |
|
62081f0b60 | 🏗️ 新增nosql模块 | 2 years ago |
|
e784154c45 | 🏗️ 新增缓存模块 | 2 years ago |
|
492ccddc35 | 🏗️ 新增多数据源模块 | 2 years ago |
|
bfc88ef348 | 🏗️ 新增ORM模块 | 2 years ago |
|
06f3b06a21 | 🏗️ 新增模板引擎模块 | 2 years ago |
|
d7b64c390f | 🏗️ 新增日志模块 | 2 years ago |
|
76c08a09d3 | 🎨 规范格式化 pom 文件 | 2 years ago |
|
30acf04233 | ✨ 应用监控模块之 admin 案例完成 | 2 years ago |
|
d1308a7b77 | ✨ 应用监控模块之 actuator 案例完成 | 2 years ago |
|
be551a61ab | 🏗️ 新增应用监控模块 | 2 years ago |
|
1dfc502479 | ✨ 基础模块之 properties 案例完成 | 2 years ago |
|
f67d01baa5 | 👷 更新 CI 流程 | 2 years ago |
|
33e9a1a44f | 👷 更新 CI 流程 | 2 years ago |
|
8247085a66 | ✨ 基础模块之 helloworld 案例完成 | 2 years ago |
|
414f478bd6 | 🏗️ 新增基础模块 | 2 years ago |
|
e221c21666 | ✨ admin 模块完成 | 2 years ago |
|
46f6e5223c | ✨ admin 模块完成 | 2 years ago |
|
76b4d23228 | 👷 更新 CI 流程 | 2 years ago |
|
2380c6985f | 👷 更新 CI 流程 | 2 years ago |
|
0cdef78b38 | 📝 修改 actuator demo 的 README 文件 | 2 years ago |
|
13b33c5113 | ✨ actuator 完成 | 2 years ago |
|
1ed0db86fa | 📝 修改 properties demo 的 README 文件 | 2 years ago |
|
9fd8d074db | ⚰️ 移除模块 ignore 文件 | 2 years ago |
|
a264c98aa6 | 🎨 规范格式化 pom 文件 | 2 years ago |
|
7ca0de590c | ✨ property 完成 | 2 years ago |
|
0f4576f5a9 | ✨ property 完成 | 2 years ago |
|
fd898aca44 | ➕ 新增 lombok 依赖 | 2 years ago |
|
e92ae11879 | 📝 修改 helloworld demo 的 README 文件 | 2 years ago |
|
84cd41e3a0 | ✨ hello,world 完成 | 2 years ago |
|
c8f5da7266 | 👷 更新 CI 流程 | 2 years ago |
|
0b221e16f3 | 👷 更新 CI 流程 | 2 years ago |
|
dfdc3a50a7 | 🔥 移除涂鸦JD | 2 years ago |
|
052549905a | ✨ hello,world 完成 | 2 years ago |
|
8ab341caae | ⬆️ 升级 jdk 版本为 17,适配 spring boot 3.x | 2 years ago |
|
4548740dc4 | ♻️ 抽取通用工具类模块,减少后续模块的重复代码 | 2 years ago |
|
ce226dcc2e | ♻️ 升级spring boot版本到3.x | 2 years ago |
|
a7d1c92da3 | 💥 升级spring boot版本为2.7.2,为后期3.x做准备 | 2 years ago |
@@ -0,0 +1,44 @@ | |||||
kind: pipeline | |||||
type: docker | |||||
name: build | |||||
steps: | |||||
- name: compile | |||||
image: maven:3.8.6-amazoncorretto-17 | |||||
pull: if-not-exists | |||||
volumes: | |||||
- name: mvn_cache | |||||
path: /root/.m2 | |||||
commands: | |||||
- mvn clean package -DskipTests -Dmaven.javadoc.skip=true -B -V | |||||
- name: notification-success | |||||
image: yakumioto/drone-serverchan:2.0.0 | |||||
settings: | |||||
key: | |||||
from_secret: sc_key | |||||
text: "[CI通知]-[${DRONE_REPO_NAME}]✅" | |||||
desp: "仓库:${DRONE_REPO} 分支:`${DRONE_COMMIT_BRANCH}`\n\n💬 状态:第 **${DRONE_BUILD_NUMBER}** 次编译成功\n\n🌐 详情:[CI地址](${DRONE_BUILD_LINK})\n\n📄 内容:[diff](${DRONE_COMMIT_LINK})" | |||||
when: | |||||
status: | |||||
- success | |||||
- name: notification-failure | |||||
image: yakumioto/drone-serverchan:2.0.0 | |||||
settings: | |||||
key: | |||||
from_secret: sc_key | |||||
text: "[CI通知]-[${DRONE_REPO_NAME}]❌" | |||||
desp: "仓库:${DRONE_REPO} 分支:`${DRONE_COMMIT_BRANCH}`\n\n💬 状态:第 **${DRONE_BUILD_NUMBER}** 次编译失败\n\n🌐 详情:[CI地址](${DRONE_BUILD_LINK})\n\n📄 内容:[diff](${DRONE_COMMIT_LINK})" | |||||
when: | |||||
status: | |||||
- failure | |||||
trigger: | |||||
event: | |||||
- push | |||||
volumes: | |||||
- name: mvn_cache # The name use in this pipeline, | |||||
host: | |||||
path: /root/.m2 # The path be used in the host. |
@@ -0,0 +1,20 @@ | |||||
# This workflow will build a Java project with Maven, and cache/restore any dependencies to improve the workflow execution time | |||||
# For more information see: https://help.github.com/actions/language-and-framework-guides/building-and-testing-java-with-maven | |||||
name: 自动化编译检查 | |||||
on: [ push ] | |||||
jobs: | |||||
build: | |||||
runs-on: ubuntu-latest | |||||
steps: | |||||
- uses: actions/checkout@v3 | |||||
- name: 设置 JDK 版本 | |||||
uses: actions/setup-java@v3 | |||||
with: | |||||
java-version: '17' | |||||
distribution: 'corretto' | |||||
cache: maven | |||||
- name: 编译打包 | |||||
run: mvn clean package -DskipTests -Dmaven.javadoc.skip=true -B -V |
@@ -1,17 +0,0 @@ | |||||
name: GitHub CI | |||||
on: | |||||
push: | |||||
branches: | |||||
- master | |||||
pull_request: | |||||
jobs: | |||||
build: | |||||
runs-on: ubuntu-latest | |||||
steps: | |||||
- uses: actions/checkout@v1 | |||||
- name: Set up JDK 1.8 | |||||
uses: actions/setup-java@v1 | |||||
with: | |||||
java-version: 1.8 | |||||
- name: Build with Maven | |||||
run: mvn clean package -DskipTests=true -Dmaven.javadoc.skip=true -B -V |
@@ -38,3 +38,5 @@ logs/ | |||||
### VS CODE ### | ### VS CODE ### | ||||
.vscode/ | .vscode/ | ||||
tmp/ |
@@ -1,19 +0,0 @@ | |||||
# 语言 | |||||
language: java | |||||
# 执行脚本 | |||||
script: "mvn clean package -DskipTests=true -Dmaven.javadoc.skip=true -B -V" | |||||
# 通知 | |||||
notifications: | |||||
email: | |||||
recipients: | |||||
- 237497819@qq.com | |||||
on_success: always # default: change | |||||
on_failure: always # default: always | |||||
# 缓存 | |||||
cache: | |||||
directories: | |||||
- '$HOME/.m2/repository' | |||||
branches: | |||||
only: | |||||
- master |
@@ -108,7 +108,7 @@ View the [TODO](./TODO.en.md) file | |||||
| [demo-mq-rabbitmq](./demo-mq-rabbitmq) | a demo to integrate RabbitMQ implementation for message delivery and reception based on direct queue mode, fanout mode, topic mode, delay queue. | | | [demo-mq-rabbitmq](./demo-mq-rabbitmq) | a demo to integrate RabbitMQ implementation for message delivery and reception based on direct queue mode, fanout mode, topic mode, delay queue. | | ||||
| [demo-mq-rocketmq](./demo-mq-rocketmq) | <span style="color:pink;">NOT FINISHED YET!</span> <br />a demo to integrate RocketMQ implementation for message delivery and reception. | | | [demo-mq-rocketmq](./demo-mq-rocketmq) | <span style="color:pink;">NOT FINISHED YET!</span> <br />a demo to integrate RocketMQ implementation for message delivery and reception. | | ||||
| [demo-mq-kafka](./demo-mq-kafka) | a demo to integrate Kafka implementation for message delivery and reception. | | | [demo-mq-kafka](./demo-mq-kafka) | a demo to integrate Kafka implementation for message delivery and reception. | | ||||
| [demo-websocket](./demo-websocket) | a demo to integrate websocket, the backend actively pushes the server running status to front end. | | |||||
| [demo-websocket](./demo-websocket-spring) | a demo to integrate websocket, the backend actively pushes the server running status to front end. | | |||||
| [demo-websocket-socketio](./demo-websocket-socketio) | a demo to integrate websocket by using `netty-socketio`, implement a simple chat room. | | | [demo-websocket-socketio](./demo-websocket-socketio) | a demo to integrate websocket by using `netty-socketio`, implement a simple chat room. | | ||||
| [demo-ureport2](./demo-ureport2) | <span style="color:pink;">NOT FINISHED YET!</span> <br />a demo to integrate [ureport2](https://github.com/youseries/ureport) to implement complex, customized Chinese-style reports. | | | [demo-ureport2](./demo-ureport2) | <span style="color:pink;">NOT FINISHED YET!</span> <br />a demo to integrate [ureport2](https://github.com/youseries/ureport) to implement complex, customized Chinese-style reports. | | ||||
| [demo-uflo](./demo-uflo) | <span style="color:pink;">NOT FINISHED YET!</span> <br />a demo to integrate [uflo](https://github.com/youseries/uflo)(process engine like Activiti and Flowable) to quickly implement a lightweight process engine. | | | [demo-uflo](./demo-uflo) | <span style="color:pink;">NOT FINISHED YET!</span> <br />a demo to integrate [uflo](https://github.com/youseries/uflo)(process engine like Activiti and Flowable) to quickly implement a lightweight process engine. | | ||||
@@ -56,10 +56,6 @@ | |||||
## 其他 | ## 其他 | ||||
### 团队纳新 | |||||
组内招人啦,HC 巨多,Base 杭州,感兴趣的小伙伴,查看 [岗位详情](./jd.md) | |||||
### 开源推荐 | ### 开源推荐 | ||||
 |  | ||||
@@ -114,7 +110,7 @@ | |||||
| [demo-mq-rabbitmq](./demo-mq-rabbitmq) | spring-boot 集成 RabbitMQ 实现基于直接队列模式、分列模式、主题模式、延迟队列的消息发送和接收 | | | [demo-mq-rabbitmq](./demo-mq-rabbitmq) | spring-boot 集成 RabbitMQ 实现基于直接队列模式、分列模式、主题模式、延迟队列的消息发送和接收 | | ||||
| [demo-mq-rocketmq](./demo-mq-rocketmq) | spring-boot 集成 RocketMQ,实现消息的发送和接收<br /> <span style="color:pink;">待完成</span> | | | [demo-mq-rocketmq](./demo-mq-rocketmq) | spring-boot 集成 RocketMQ,实现消息的发送和接收<br /> <span style="color:pink;">待完成</span> | | ||||
| [demo-mq-kafka](./demo-mq-kafka) | spring-boot 集成 kafka,实现消息的发送和接收 | | | [demo-mq-kafka](./demo-mq-kafka) | spring-boot 集成 kafka,实现消息的发送和接收 | | ||||
| [demo-websocket](./demo-websocket) | spring-boot 集成 websocket,后端主动推送前端服务器运行信息 | | |||||
| [demo-websocket](./demo-websocket-spring) | spring-boot 集成 websocket,后端主动推送前端服务器运行信息 | | |||||
| [demo-websocket-socketio](./demo-websocket-socketio) | spring-boot 使用 netty-socketio 集成 websocket,实现一个简单的聊天室 | | | [demo-websocket-socketio](./demo-websocket-socketio) | spring-boot 使用 netty-socketio 集成 websocket,实现一个简单的聊天室 | | ||||
| [demo-ureport2](./demo-ureport2) | spring-boot 集成 ureport2 实现复杂的自定义的中国式报表<br /> <span style="color:pink;">待完成</span> | | | [demo-ureport2](./demo-ureport2) | spring-boot 集成 ureport2 实现复杂的自定义的中国式报表<br /> <span style="color:pink;">待完成</span> | | ||||
| [demo-uflo](./demo-uflo) | spring-boot 集成 uflo 快速实现轻量级流程引擎<br /> <span style="color:pink;">待完成</span> | | | [demo-uflo](./demo-uflo) | spring-boot 集成 uflo 快速实现轻量级流程引擎<br /> <span style="color:pink;">待完成</span> | | ||||
@@ -144,12 +140,12 @@ | |||||
| [demo-flyway](./demo-flyway) | spring boot 集成 Flyway,项目启动时初始化数据库表结构,同时支持数据库脚本版本控制 | | | [demo-flyway](./demo-flyway) | spring boot 集成 Flyway,项目启动时初始化数据库表结构,同时支持数据库脚本版本控制 | | ||||
| [demo-ureport2](./demo-ureport2) | spring boot 集成 Ureport2,实现中国式复杂报表设计 | | | [demo-ureport2](./demo-ureport2) | spring boot 集成 Ureport2,实现中国式复杂报表设计 | | ||||
### 感谢 | |||||
### 特别感谢 | |||||
- 感谢 [七牛云](https://portal.qiniu.com/signup?utm_source=kaiyuan&utm_media=xkcoding) 提供的免费云存储与 CDN 加速支持 | |||||
- 感谢史上最牛的代码生成插件 [MyBatisCodeHelper-Pro](https://gejun123456.github.io/MyBatisCodeHelper-Pro/#/?id=mybatiscodehelper-pro) 提供的永久激活码 | |||||
- <a href="https://www.jetbrains.com/?from=spring-boot-demo"><img src="http://static.xkcoding.com/spring-boot-demo/064312.jpg" width="100px" alt="jetbrains">**感谢 JetBrains 提供的免费开源 License**</a> | - <a href="https://www.jetbrains.com/?from=spring-boot-demo"><img src="http://static.xkcoding.com/spring-boot-demo/064312.jpg" width="100px" alt="jetbrains">**感谢 JetBrains 提供的免费开源 License**</a> | ||||
- [感谢史上最牛的代码生成插件 MyBatisCodeHelper-Pro 提供的永久激活码](https://gejun123456.github.io/MyBatisCodeHelper-Pro/#/?id=mybatiscodehelper-pro) | |||||
### License | ### License | ||||
[MIT](http://opensource.org/licenses/MIT) | [MIT](http://opensource.org/licenses/MIT) | ||||
@@ -0,0 +1,51 @@ | |||||
<?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>com.xkcoding</groupId> | |||||
<artifactId>spring-boot-demo</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
</parent> | |||||
<modelVersion>4.0.0</modelVersion> | |||||
<artifactId>common-tools</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
<packaging>jar</packaging> | |||||
<name>${project.artifactId}</name> | |||||
<description>通用工具类、通用依赖</description> | |||||
<properties> | |||||
<java.version>17</java.version> | |||||
</properties> | |||||
<dependencies> | |||||
<dependency> | |||||
<groupId>cn.hutool</groupId> | |||||
<artifactId>hutool-all</artifactId> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>com.google.guava</groupId> | |||||
<artifactId>guava</artifactId> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>io.swagger.core.v3</groupId> | |||||
<artifactId>swagger-annotations-jakarta</artifactId> | |||||
<version>2.2.2</version> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>org.projectlombok</groupId> | |||||
<artifactId>lombok</artifactId> | |||||
<optional>true</optional> | |||||
</dependency> | |||||
</dependencies> | |||||
<build> | |||||
<finalName>${project.artifactId}</finalName> | |||||
</build> | |||||
</project> |
@@ -0,0 +1,26 @@ | |||||
package com.xkcoding.common.enums; | |||||
import com.xkcoding.common.enums.base.IStatus; | |||||
import lombok.AllArgsConstructor; | |||||
import lombok.Getter; | |||||
/** | |||||
* 常用状态 | |||||
* | |||||
* @author yangkai.shen | |||||
* @date 2022-08-20 01:49 | |||||
*/ | |||||
@Getter | |||||
@AllArgsConstructor | |||||
public enum CommonStatus implements IStatus { | |||||
/** | |||||
* 操作状态码 | |||||
*/ | |||||
OK(200, "请求成功"), | |||||
BASE_ERROR(202, "基础服务异常"), | |||||
PARAM_ERROR(203, "请求参数缺失"), | |||||
SERVER_ERROR(500, "系统错误,请联系管理员"); | |||||
private final Integer code; | |||||
private final String desc; | |||||
} |
@@ -0,0 +1,23 @@ | |||||
package com.xkcoding.common.enums.base; | |||||
/** | |||||
* 状态抽象 | |||||
* | |||||
* @author yangkai.shen | |||||
* @date 2022-08-20 01:49 | |||||
*/ | |||||
public interface IStatus { | |||||
/** | |||||
* 状态码 | |||||
* | |||||
* @return 状态码 | |||||
*/ | |||||
Integer getCode(); | |||||
/** | |||||
* 描述 | |||||
* | |||||
* @return 描述 | |||||
*/ | |||||
String getDesc(); | |||||
} |
@@ -0,0 +1,43 @@ | |||||
package com.xkcoding.common.exception; | |||||
import com.xkcoding.common.enums.CommonStatus; | |||||
import com.xkcoding.common.enums.base.IStatus; | |||||
import lombok.Data; | |||||
import lombok.EqualsAndHashCode; | |||||
/** | |||||
* 通用业务异常 | |||||
* | |||||
* @author yangkai.shen | |||||
* @date 2022-08-20 01:55 | |||||
*/ | |||||
@Data | |||||
@EqualsAndHashCode(callSuper = true) | |||||
public class CommonBizException extends RuntimeException { | |||||
public Integer code; | |||||
private String message; | |||||
public CommonBizException(Integer code, String message) { | |||||
super(message); | |||||
this.code = code; | |||||
this.message = message; | |||||
} | |||||
public CommonBizException(Throwable cause) { | |||||
super(cause); | |||||
this.code = CommonStatus.SERVER_ERROR.getCode(); | |||||
this.message = cause.getMessage(); | |||||
} | |||||
public CommonBizException(String message) { | |||||
super(message); | |||||
this.code = CommonStatus.SERVER_ERROR.getCode(); | |||||
this.message = message; | |||||
} | |||||
public CommonBizException(IStatus status) { | |||||
super(status.getDesc()); | |||||
this.code = status.getCode(); | |||||
this.message = status.getDesc(); | |||||
} | |||||
} |
@@ -0,0 +1,70 @@ | |||||
package com.xkcoding.common.model.viewmodel; | |||||
import com.xkcoding.common.enums.CommonStatus; | |||||
import com.xkcoding.common.enums.base.IStatus; | |||||
import com.xkcoding.common.exception.CommonBizException; | |||||
import io.swagger.v3.oas.annotations.media.Schema; | |||||
import lombok.Data; | |||||
import java.io.Serializable; | |||||
/** | |||||
* 通用接口返回 | |||||
* | |||||
* @author yangkai.shen | |||||
* @date 2022-08-20 01:43 | |||||
*/ | |||||
@Data | |||||
@Schema(name = "Response", title = "通用PI接口返回", description = "Common Api Response") | |||||
public class Response<T> implements Serializable { | |||||
/** | |||||
* 状态码 | |||||
*/ | |||||
@Schema(title = "状态码", required = true) | |||||
private Integer code; | |||||
/** | |||||
* 返回内容 | |||||
*/ | |||||
@Schema(title = "返回内容", required = true) | |||||
private String message; | |||||
/** | |||||
* 返回数据 | |||||
*/ | |||||
@Schema(title = "返回数据", required = false) | |||||
private T data; | |||||
private Response() { | |||||
} | |||||
private Response(Integer code, String message, T data) { | |||||
this.code = code; | |||||
this.message = message; | |||||
this.data = data; | |||||
} | |||||
public static <T> Response<T> of(Integer code, String message, T data) { | |||||
return new Response<>(code, message, data); | |||||
} | |||||
public static <T> Response<T> ofSuccess(T data) { | |||||
return ofStatus(CommonStatus.OK, data); | |||||
} | |||||
public static <T> Response<T> ofStatus(IStatus status) { | |||||
return ofStatus(status, null); | |||||
} | |||||
public static <T> Response<T> ofStatus(IStatus status, T data) { | |||||
return of(status.getCode(), status.getDesc(), data); | |||||
} | |||||
public static <T> Response<T> ofError(CommonBizException exception, T data) { | |||||
return of(exception.getCode(), exception.getMessage(), data); | |||||
} | |||||
public static <T> Response<T> ofError(CommonBizException exception) { | |||||
return ofError(exception, null); | |||||
} | |||||
} |
@@ -1,71 +0,0 @@ | |||||
<?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>demo-activiti</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
<packaging>jar</packaging> | |||||
<name>demo-activiti</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-web</artifactId> | |||||
</dependency> | |||||
<!-- activiti 自动建表 --> | |||||
<dependency> | |||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-starter-jdbc</artifactId> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>org.activiti</groupId> | |||||
<artifactId>activiti-spring-boot-starter</artifactId> | |||||
<version>7.1.0.M2</version> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-starter-test</artifactId> | |||||
<scope>test</scope> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>mysql</groupId> | |||||
<artifactId>mysql-connector-java</artifactId> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>org.projectlombok</groupId> | |||||
<artifactId>lombok</artifactId> | |||||
<optional>true</optional> | |||||
</dependency> | |||||
</dependencies> | |||||
<build> | |||||
<finalName>demo-activiti</finalName> | |||||
<plugins> | |||||
<plugin> | |||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-maven-plugin</artifactId> | |||||
</plugin> | |||||
</plugins> | |||||
</build> | |||||
</project> |
@@ -1,22 +0,0 @@ | |||||
package com.xkcoding.activiti; | |||||
import org.springframework.boot.SpringApplication; | |||||
import org.springframework.boot.autoconfigure.SpringBootApplication; | |||||
/** | |||||
* <p> | |||||
* 启动器 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2019-03-31 22:24 | |||||
*/ | |||||
@SpringBootApplication | |||||
public class SpringBootDemoActivitiApplication { | |||||
public static void main(String[] args) { | |||||
SpringApplication.run(SpringBootDemoActivitiApplication.class, args); | |||||
} | |||||
} | |||||
@@ -1,56 +0,0 @@ | |||||
package com.xkcoding.activiti.config; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.context.annotation.Bean; | |||||
import org.springframework.context.annotation.Configuration; | |||||
import org.springframework.security.config.annotation.authentication.builders.AuthenticationManagerBuilder; | |||||
import org.springframework.security.config.annotation.web.configuration.WebSecurityConfigurerAdapter; | |||||
import org.springframework.security.core.authority.SimpleGrantedAuthority; | |||||
import org.springframework.security.core.userdetails.User; | |||||
import org.springframework.security.core.userdetails.UserDetailsService; | |||||
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder; | |||||
import org.springframework.security.crypto.password.PasswordEncoder; | |||||
import org.springframework.security.provisioning.InMemoryUserDetailsManager; | |||||
import java.util.Arrays; | |||||
import java.util.List; | |||||
import java.util.stream.Collectors; | |||||
/** | |||||
* <p> | |||||
* 安全配置类 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2019-07-01 18:40 | |||||
*/ | |||||
@Slf4j | |||||
@Configuration | |||||
public class SecurityConfiguration extends WebSecurityConfigurerAdapter { | |||||
@Override | |||||
protected void configure(AuthenticationManagerBuilder auth) throws Exception { | |||||
auth.userDetailsService(userDetailsService()); | |||||
} | |||||
@Bean | |||||
protected UserDetailsService myUserDetailsService() { | |||||
InMemoryUserDetailsManager inMemoryUserDetailsManager = new InMemoryUserDetailsManager(); | |||||
String[][] usersGroupsAndRoles = {{"salaboy", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"}, {"ryandawsonuk", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"}, {"erdemedeiros", "password", "ROLE_ACTIVITI_USER", "GROUP_activitiTeam"}, {"other", "password", "ROLE_ACTIVITI_USER", "GROUP_otherTeam"}, {"admin", "password", "ROLE_ACTIVITI_ADMIN"}}; | |||||
for (String[] user : usersGroupsAndRoles) { | |||||
List<String> authoritiesStrings = Arrays.asList(Arrays.copyOfRange(user, 2, user.length)); | |||||
log.info("> Registering new user: " + user[0] + " with the following Authorities[" + authoritiesStrings + "]"); | |||||
inMemoryUserDetailsManager.createUser(new User(user[0], passwordEncoder().encode(user[1]), authoritiesStrings.stream().map(SimpleGrantedAuthority::new).collect(Collectors.toList()))); | |||||
} | |||||
return inMemoryUserDetailsManager; | |||||
} | |||||
@Bean | |||||
public PasswordEncoder passwordEncoder() { | |||||
return new BCryptPasswordEncoder(); | |||||
} | |||||
} |
@@ -1,74 +0,0 @@ | |||||
package com.xkcoding.activiti.util; | |||||
import lombok.RequiredArgsConstructor; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.security.core.Authentication; | |||||
import org.springframework.security.core.GrantedAuthority; | |||||
import org.springframework.security.core.context.SecurityContextHolder; | |||||
import org.springframework.security.core.context.SecurityContextImpl; | |||||
import org.springframework.security.core.userdetails.UserDetails; | |||||
import org.springframework.security.core.userdetails.UserDetailsService; | |||||
import org.springframework.stereotype.Component; | |||||
import java.util.Collection; | |||||
/** | |||||
* <p> | |||||
* 认证工具 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2019-07-01 18:38 | |||||
*/ | |||||
@Component | |||||
@RequiredArgsConstructor(onConstructor_ = @Autowired) | |||||
public class SecurityUtil { | |||||
private final UserDetailsService userDetailsService; | |||||
public void logInAs(String username) { | |||||
UserDetails user = userDetailsService.loadUserByUsername(username); | |||||
if (user == null) { | |||||
throw new IllegalStateException("User " + username + " doesn't exist, please provide a valid user"); | |||||
} | |||||
SecurityContextHolder.setContext(new SecurityContextImpl(new Authentication() { | |||||
@Override | |||||
public Collection<? extends GrantedAuthority> getAuthorities() { | |||||
return user.getAuthorities(); | |||||
} | |||||
@Override | |||||
public Object getCredentials() { | |||||
return user.getPassword(); | |||||
} | |||||
@Override | |||||
public Object getDetails() { | |||||
return user; | |||||
} | |||||
@Override | |||||
public Object getPrincipal() { | |||||
return user; | |||||
} | |||||
@Override | |||||
public boolean isAuthenticated() { | |||||
return true; | |||||
} | |||||
@Override | |||||
public void setAuthenticated(boolean isAuthenticated) throws IllegalArgumentException { | |||||
} | |||||
@Override | |||||
public String getName() { | |||||
return user.getUsername(); | |||||
} | |||||
})); | |||||
org.activiti.engine.impl.identity.Authentication.setAuthenticatedUserId(username); | |||||
} | |||||
} |
@@ -1,16 +0,0 @@ | |||||
spring: | |||||
datasource: | |||||
url: jdbc:mysql://localhost:3306/spring-boot-demo | |||||
username: root | |||||
password: root | |||||
hikari: | |||||
data-source-properties: | |||||
useSSL: false | |||||
serverTimezone: GMT+8 | |||||
useUnicode: true | |||||
characterEncoding: utf8 | |||||
# 这个必须要加,否则 Activiti 自动建表会失败 | |||||
nullCatalogMeansCurrent: true | |||||
activiti: | |||||
history-level: full | |||||
db-history-used: true |
@@ -1,78 +0,0 @@ | |||||
<?xml version="1.0" encoding="UTF-8" standalone="yes"?> | |||||
<definitions xmlns="http://www.omg.org/spec/BPMN/20100524/MODEL" xmlns:activiti="http://activiti.org/bpmn" xmlns:bpmndi="http://www.omg.org/spec/BPMN/20100524/DI" xmlns:omgdc="http://www.omg.org/spec/DD/20100524/DC" xmlns:omgdi="http://www.omg.org/spec/DD/20100524/DI" xmlns:tns="http://www.activiti.org/test" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:yaoqiang="http://bpmn.sourceforge.net" exporter="Yaoqiang BPMN Editor" exporterVersion="5.3" expressionLanguage="http://www.w3.org/1999/XPath" id="m1544167269809" name="" targetNamespace="http://www.activiti.org/test" typeLanguage="http://www.w3.org/2001/XMLSchema" xsi:schemaLocation="http://www.omg.org/spec/BPMN/20100524/MODEL http://bpmn.sourceforge.net/schemas/BPMN20.xsd"> | |||||
<process id="myProcess_1" isClosed="false" isExecutable="true" processType="None"> | |||||
<extensionElements> | |||||
<yaoqiang:description/> | |||||
<yaoqiang:pageFormat height="841.8897637795276" imageableHeight="831.8897637795276" imageableWidth="588.1102362204724" imageableX="5.0" imageableY="5.0" orientation="0" width="598.1102362204724"/> | |||||
<yaoqiang:page background="#FFFFFF" horizontalCount="1" verticalCount="1"/> | |||||
</extensionElements> | |||||
<startEvent id="_2" isInterrupting="true" name="StartEvent" parallelMultiple="false"> | |||||
<outgoing>_6</outgoing> | |||||
<outputSet/> | |||||
</startEvent> | |||||
<userTask activiti:candidateGroups="activitiTeam" activiti:exclusive="true" completionQuantity="1" id="_3" implementation="##unspecified" isForCompensation="false" name="first" startQuantity="1"> | |||||
<incoming>_6</incoming> | |||||
<outgoing>_7</outgoing> | |||||
</userTask> | |||||
<userTask activiti:candidateGroups="activitiTeam" activiti:exclusive="true" completionQuantity="1" id="_4" implementation="##unspecified" isForCompensation="false" name="second" startQuantity="1"> | |||||
<incoming>_7</incoming> | |||||
<outgoing>_8</outgoing> | |||||
</userTask> | |||||
<endEvent id="_5" name="EndEvent"> | |||||
<incoming>_8</incoming> | |||||
<inputSet/> | |||||
</endEvent> | |||||
<sequenceFlow id="_6" sourceRef="_2" targetRef="_3"/> | |||||
<sequenceFlow id="_7" sourceRef="_3" targetRef="_4"/> | |||||
<sequenceFlow id="_8" sourceRef="_4" targetRef="_5"/> | |||||
</process> | |||||
<bpmndi:BPMNDiagram id="Yaoqiang_Diagram-myProcess_1" name="New Diagram" resolution="96.0"> | |||||
<bpmndi:BPMNPlane bpmnElement="myProcess_1"> | |||||
<bpmndi:BPMNShape bpmnElement="_2" id="Yaoqiang-_2"> | |||||
<omgdc:Bounds height="32.0" width="32.0" x="65.0" y="80.0"/> | |||||
<bpmndi:BPMNLabel> | |||||
<omgdc:Bounds height="18.96" width="60.0" x="51.0" y="120.52"/> | |||||
</bpmndi:BPMNLabel> | |||||
</bpmndi:BPMNShape> | |||||
<bpmndi:BPMNShape bpmnElement="_3" id="Yaoqiang-_3"> | |||||
<omgdc:Bounds height="55.0" width="85.0" x="170.0" y="115.0"/> | |||||
<bpmndi:BPMNLabel> | |||||
<omgdc:Bounds height="18.96" width="28.0" x="198.5" y="135.02"/> | |||||
</bpmndi:BPMNLabel> | |||||
</bpmndi:BPMNShape> | |||||
<bpmndi:BPMNShape bpmnElement="_4" id="Yaoqiang-_4"> | |||||
<omgdc:Bounds height="55.0" width="85.0" x="310.0" y="155.0"/> | |||||
<bpmndi:BPMNLabel> | |||||
<omgdc:Bounds height="18.96" width="45.0" x="330.0" y="175.02"/> | |||||
</bpmndi:BPMNLabel> | |||||
</bpmndi:BPMNShape> | |||||
<bpmndi:BPMNShape bpmnElement="_5" id="Yaoqiang-_5"> | |||||
<omgdc:Bounds height="32.0" width="32.0" x="505.0" y="220.0"/> | |||||
<bpmndi:BPMNLabel> | |||||
<omgdc:Bounds height="18.96" width="55.0" x="493.5" y="260.52"/> | |||||
</bpmndi:BPMNLabel> | |||||
</bpmndi:BPMNShape> | |||||
<bpmndi:BPMNEdge bpmnElement="_8" id="Yaoqiang-_8"> | |||||
<omgdi:waypoint x="395.0" y="182.5"/> | |||||
<omgdi:waypoint x="505.0" y="236.0"/> | |||||
<bpmndi:BPMNLabel> | |||||
<omgdc:Bounds height="18.96" width="6.0" x="447.0" y="199.77"/> | |||||
</bpmndi:BPMNLabel> | |||||
</bpmndi:BPMNEdge> | |||||
<bpmndi:BPMNEdge bpmnElement="_7" id="Yaoqiang-_7"> | |||||
<omgdi:waypoint x="255.0" y="142.5"/> | |||||
<omgdi:waypoint x="310.0" y="182.5"/> | |||||
<bpmndi:BPMNLabel> | |||||
<omgdc:Bounds height="18.96" width="6.0" x="279.5" y="153.02"/> | |||||
</bpmndi:BPMNLabel> | |||||
</bpmndi:BPMNEdge> | |||||
<bpmndi:BPMNEdge bpmnElement="_6" id="Yaoqiang-_6"> | |||||
<omgdi:waypoint x="97.0" y="96.0"/> | |||||
<omgdi:waypoint x="170.0" y="142.5"/> | |||||
<bpmndi:BPMNLabel> | |||||
<omgdc:Bounds height="18.96" width="6.0" x="130.5" y="109.77"/> | |||||
</bpmndi:BPMNLabel> | |||||
</bpmndi:BPMNEdge> | |||||
</bpmndi:BPMNPlane> | |||||
</bpmndi:BPMNDiagram> | |||||
</definitions> |
@@ -1,31 +0,0 @@ | |||||
package com.xkcoding.activiti; | |||||
import com.xkcoding.activiti.util.SecurityUtil; | |||||
import org.activiti.api.process.model.ProcessDefinition; | |||||
import org.activiti.api.process.runtime.ProcessRuntime; | |||||
import org.activiti.api.runtime.shared.query.Page; | |||||
import org.activiti.api.runtime.shared.query.Pageable; | |||||
import org.junit.Test; | |||||
import org.junit.runner.RunWith; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import org.springframework.boot.test.context.SpringBootTest; | |||||
import org.springframework.test.context.junit4.SpringRunner; | |||||
@RunWith(SpringRunner.class) | |||||
@SpringBootTest | |||||
public class SpringBootDemoActivitiApplicationTests { | |||||
@Autowired | |||||
private ProcessRuntime processRuntime; | |||||
@Autowired | |||||
private SecurityUtil securityUtil; | |||||
@Test | |||||
public void contextLoads() { | |||||
securityUtil.logInAs("salaboy"); | |||||
Page<ProcessDefinition> processDefinitionPage = processRuntime.processDefinitions(Pageable.of(0, 10)); | |||||
processDefinitionPage.getContent().forEach(System.out::println); | |||||
} | |||||
} | |||||
@@ -1,114 +0,0 @@ | |||||
# 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 |
@@ -1,64 +0,0 @@ | |||||
<?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>demo-actuator</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
<packaging>jar</packaging> | |||||
<name>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>demo-actuator</finalName> | |||||
<plugins> | |||||
<plugin> | |||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-maven-plugin</artifactId> | |||||
</plugin> | |||||
</plugins> | |||||
</build> | |||||
</project> |
@@ -1,20 +0,0 @@ | |||||
package com.xkcoding.actuator; | |||||
import org.springframework.boot.SpringApplication; | |||||
import org.springframework.boot.autoconfigure.SpringBootApplication; | |||||
/** | |||||
* <p> | |||||
* 启动类 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2018-9-29 14:27 | |||||
*/ | |||||
@SpringBootApplication | |||||
public class SpringBootDemoActuatorApplication { | |||||
public static void main(String[] args) { | |||||
SpringApplication.run(SpringBootDemoActuatorApplication.class, args); | |||||
} | |||||
} |
@@ -1,25 +0,0 @@ | |||||
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,16 +0,0 @@ | |||||
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() { | |||||
} | |||||
} |
@@ -1,51 +0,0 @@ | |||||
# spring-boot-demo-admin | |||||
> 本 demo 主要演示了 Spring Boot 如何集成 Admin 管控台,监控管理 Spring Boot 应用,分别为 admin 服务端和 admin 客户端,两个模块。 | |||||
## 运行步骤 | |||||
1. 进入 `spring-boot-demo-admin-server` 服务端,启动管控台服务端程序 | |||||
2. 进入 `spring-boot-demo-admin-client` 客户端,启动客户端程序,注册到服务端 | |||||
3. 观察服务端里,客户端程序的运行状态等信息 | |||||
## 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"> | |||||
<parent> | |||||
<artifactId>spring-boot-demo</artifactId> | |||||
<groupId>com.xkcoding</groupId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
</parent> | |||||
<modelVersion>4.0.0</modelVersion> | |||||
<artifactId>spring-boot-demo-admin</artifactId> | |||||
<packaging>pom</packaging> | |||||
<properties> | |||||
<spring-boot-admin.version>2.1.0</spring-boot-admin.version> | |||||
</properties> | |||||
<modules> | |||||
<module>spring-boot-demo-admin-client</module> | |||||
<module>spring-boot-demo-admin-server</module> | |||||
</modules> | |||||
<dependencyManagement> | |||||
<dependencies> | |||||
<dependency> | |||||
<groupId>de.codecentric</groupId> | |||||
<artifactId>spring-boot-admin-dependencies</artifactId> | |||||
<version>${spring-boot-admin.version}</version> | |||||
<type>pom</type> | |||||
<scope>import</scope> | |||||
</dependency> | |||||
</dependencies> | |||||
</dependencyManagement> | |||||
</project> | |||||
``` | |||||
@@ -1,104 +0,0 @@ | |||||
# spring-boot-demo-admin-client | |||||
> 本 demo 主要演示了普通项目如何集成 Spring Boot Admin,并把自己的运行状态交给 Spring Boot Admin 进行展现。 | |||||
## 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-admin-client</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
<packaging>jar</packaging> | |||||
<name>spring-boot-demo-admin-client</name> | |||||
<description>Demo project for Spring Boot</description> | |||||
<parent> | |||||
<groupId>com.xkcoding</groupId> | |||||
<artifactId>spring-boot-demo-admin</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-web</artifactId> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>de.codecentric</groupId> | |||||
<artifactId>spring-boot-admin-starter-client</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-test</artifactId> | |||||
<scope>test</scope> | |||||
</dependency> | |||||
</dependencies> | |||||
<build> | |||||
<finalName>spring-boot-demo-admin-client</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: | |||||
application: | |||||
# Spring Boot Admin展示的客户端项目名,不设置,会使用自动生成的随机id | |||||
name: spring-boot-demo-admin-client | |||||
boot: | |||||
admin: | |||||
client: | |||||
# Spring Boot Admin 服务端地址 | |||||
url: "http://localhost:8000/" | |||||
instance: | |||||
metadata: | |||||
# 客户端端点信息的安全认证信息 | |||||
user.name: ${spring.security.user.name} | |||||
user.password: ${spring.security.user.password} | |||||
security: | |||||
user: | |||||
name: xkcoding | |||||
password: 123456 | |||||
management: | |||||
endpoint: | |||||
health: | |||||
# 端点健康情况,默认值"never",设置为"always"可以显示硬盘使用情况和线程情况 | |||||
show-details: always | |||||
endpoints: | |||||
web: | |||||
exposure: | |||||
# 设置端点暴露的哪些内容,默认["health","info"],设置"*"代表暴露所有可访问的端点 | |||||
include: "*" | |||||
``` | |||||
@@ -1,57 +0,0 @@ | |||||
<?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>com.xkcoding</groupId> | |||||
<artifactId>demo-admin</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
</parent> | |||||
<modelVersion>4.0.0</modelVersion> | |||||
<artifactId>admin-client</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
<packaging>jar</packaging> | |||||
<name>admin-client</name> | |||||
<description>Demo project for Spring Boot</description> | |||||
<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-web</artifactId> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>de.codecentric</groupId> | |||||
<artifactId>spring-boot-admin-starter-client</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-test</artifactId> | |||||
<scope>test</scope> | |||||
</dependency> | |||||
</dependencies> | |||||
<build> | |||||
<finalName>admin-client</finalName> | |||||
<plugins> | |||||
<plugin> | |||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-maven-plugin</artifactId> | |||||
</plugin> | |||||
</plugins> | |||||
</build> | |||||
</project> |
@@ -1,20 +0,0 @@ | |||||
package com.xkcoding.admin.client; | |||||
import org.springframework.boot.SpringApplication; | |||||
import org.springframework.boot.autoconfigure.SpringBootApplication; | |||||
/** | |||||
* <p> | |||||
* 启动类 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2018-10-8 14:16 | |||||
*/ | |||||
@SpringBootApplication | |||||
public class SpringBootDemoAdminClientApplication { | |||||
public static void main(String[] args) { | |||||
SpringApplication.run(SpringBootDemoAdminClientApplication.class, args); | |||||
} | |||||
} |
@@ -1,20 +0,0 @@ | |||||
package com.xkcoding.admin.client.controller; | |||||
import org.springframework.web.bind.annotation.GetMapping; | |||||
import org.springframework.web.bind.annotation.RestController; | |||||
/** | |||||
* <p> | |||||
* 首页 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2018-10-08 14:15 | |||||
*/ | |||||
@RestController | |||||
public class IndexController { | |||||
@GetMapping(value = {"", "/"}) | |||||
public String index() { | |||||
return "This is a Spring Boot Admin Client."; | |||||
} | |||||
} |
@@ -1,32 +0,0 @@ | |||||
server: | |||||
port: 8080 | |||||
servlet: | |||||
context-path: /demo | |||||
spring: | |||||
application: | |||||
# Spring Boot Admin展示的客户端项目名,不设置,会使用自动生成的随机id | |||||
name: spring-boot-demo-admin-client | |||||
boot: | |||||
admin: | |||||
client: | |||||
# Spring Boot Admin 服务端地址 | |||||
url: "http://localhost:8000/" | |||||
instance: | |||||
metadata: | |||||
# 客户端端点信息的安全认证信息 | |||||
user.name: ${spring.security.user.name} | |||||
user.password: ${spring.security.user.password} | |||||
security: | |||||
user: | |||||
name: xkcoding | |||||
password: 123456 | |||||
management: | |||||
endpoint: | |||||
health: | |||||
# 端点健康情况,默认值"never",设置为"always"可以显示硬盘使用情况和线程情况 | |||||
show-details: always | |||||
endpoints: | |||||
web: | |||||
exposure: | |||||
# 设置端点暴露的哪些内容,默认["health","info"],设置"*"代表暴露所有可访问的端点 | |||||
include: "*" |
@@ -1,16 +0,0 @@ | |||||
package com.xkcoding.admin.client; | |||||
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 SpringBootDemoAdminClientApplicationTests { | |||||
@Test | |||||
public void contextLoads() { | |||||
} | |||||
} |
@@ -1,90 +0,0 @@ | |||||
# spring-boot-demo-admin-server | |||||
> 本 demo 主要演示了如何搭建一个 Spring Boot Admin 的服务端项目,可视化展示自己客户端项目的运行状态。 | |||||
## 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-admin-server</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
<packaging>jar</packaging> | |||||
<name>spring-boot-demo-admin-server</name> | |||||
<description>Demo project for Spring Boot</description> | |||||
<parent> | |||||
<groupId>com.xkcoding</groupId> | |||||
<artifactId>spring-boot-demo-admin</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-web</artifactId> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>de.codecentric</groupId> | |||||
<artifactId>spring-boot-admin-starter-server</artifactId> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-starter-test</artifactId> | |||||
<scope>test</scope> | |||||
</dependency> | |||||
</dependencies> | |||||
<build> | |||||
<finalName>spring-boot-demo-admin-server</finalName> | |||||
<plugins> | |||||
<plugin> | |||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-maven-plugin</artifactId> | |||||
</plugin> | |||||
</plugins> | |||||
</build> | |||||
</project> | |||||
``` | |||||
## SpringBootDemoAdminServerApplication.java | |||||
```java | |||||
/** | |||||
* <p> | |||||
* 启动类 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2018-10-08 14:08 | |||||
*/ | |||||
@EnableAdminServer | |||||
@SpringBootApplication | |||||
public class SpringBootDemoAdminServerApplication { | |||||
public static void main(String[] args) { | |||||
SpringApplication.run(SpringBootDemoAdminServerApplication.class, args); | |||||
} | |||||
} | |||||
``` | |||||
## application.yml | |||||
```yaml | |||||
server: | |||||
port: 8000 | |||||
``` | |||||
@@ -1,52 +0,0 @@ | |||||
<?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>com.xkcoding</groupId> | |||||
<artifactId>demo-admin</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
</parent> | |||||
<modelVersion>4.0.0</modelVersion> | |||||
<artifactId>demo-admin-server</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
<packaging>jar</packaging> | |||||
<name>admin-server</name> | |||||
<description>Demo project for Spring Boot</description> | |||||
<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-web</artifactId> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>de.codecentric</groupId> | |||||
<artifactId>spring-boot-admin-starter-server</artifactId> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-starter-test</artifactId> | |||||
<scope>test</scope> | |||||
</dependency> | |||||
</dependencies> | |||||
<build> | |||||
<finalName>admin-server</finalName> | |||||
<plugins> | |||||
<plugin> | |||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-maven-plugin</artifactId> | |||||
</plugin> | |||||
</plugins> | |||||
</build> | |||||
</project> |
@@ -1,22 +0,0 @@ | |||||
package com.xkcoding.admin.server; | |||||
import de.codecentric.boot.admin.server.config.EnableAdminServer; | |||||
import org.springframework.boot.SpringApplication; | |||||
import org.springframework.boot.autoconfigure.SpringBootApplication; | |||||
/** | |||||
* <p> | |||||
* 启动类 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2018-10-08 14:08 | |||||
*/ | |||||
@EnableAdminServer | |||||
@SpringBootApplication | |||||
public class SpringBootDemoAdminServerApplication { | |||||
public static void main(String[] args) { | |||||
SpringApplication.run(SpringBootDemoAdminServerApplication.class, args); | |||||
} | |||||
} |
@@ -1,2 +0,0 @@ | |||||
server: | |||||
port: 8000 |
@@ -1,16 +0,0 @@ | |||||
package com.xkcoding.admin.server; | |||||
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 SpringBootDemoAdminServerApplicationTests { | |||||
@Test | |||||
public void contextLoads() { | |||||
} | |||||
} |
@@ -1,36 +0,0 @@ | |||||
<?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>spring-boot-demo</artifactId> | |||||
<groupId>com.xkcoding</groupId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
</parent> | |||||
<modelVersion>4.0.0</modelVersion> | |||||
<artifactId>demo-admin</artifactId> | |||||
<packaging>pom</packaging> | |||||
<properties> | |||||
<spring-boot-admin.version>2.1.0</spring-boot-admin.version> | |||||
</properties> | |||||
<modules> | |||||
<module>admin-client</module> | |||||
<module>admin-server</module> | |||||
</modules> | |||||
<dependencyManagement> | |||||
<dependencies> | |||||
<dependency> | |||||
<groupId>de.codecentric</groupId> | |||||
<artifactId>spring-boot-admin-dependencies</artifactId> | |||||
<version>${spring-boot-admin.version}</version> | |||||
<type>pom</type> | |||||
<scope>import</scope> | |||||
</dependency> | |||||
</dependencies> | |||||
</dependencyManagement> | |||||
</project> |
@@ -0,0 +1,180 @@ | |||||
# spring-boot-demo-springdoc | |||||
> 此 demo 主要演示了 Spring Boot 如何通过 Springdoc 集成 swagger | |||||
## 1.开发步骤 | |||||
### 1.1.添加依赖 | |||||
> 3.0.0-M5 依赖的 servlet 为 jakarta,目前 release 的 Springdoc 依赖的是 javax.servlet-api,需要同时使用最新的 2.0.0-M5 | |||||
```xml | |||||
<dependencies> | |||||
<dependency> | |||||
<groupId>com.xkcoding</groupId> | |||||
<artifactId>common-tools</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.springdoc</groupId> | |||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> | |||||
<version>${springdoc.version}</version> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>org.projectlombok</groupId> | |||||
<artifactId>lombok</artifactId> | |||||
<optional>true</optional> | |||||
</dependency> | |||||
</dependencies> | |||||
``` | |||||
### 1.2.编写测试接口 | |||||
```java | |||||
@Slf4j | |||||
@RestController | |||||
@RequestMapping("/user") | |||||
@Tag(name = "用户管理", description = "用户管理") | |||||
public class UserController { | |||||
@GetMapping | |||||
@Operation(summary = "条件查询(DONE)", description = "备注") | |||||
@Parameters({ | |||||
@Parameter(name = "username", description = "用户名", in = ParameterIn.QUERY, schema = @Schema(implementation = String.class), required = true) | |||||
}) | |||||
public Response<User> getByUserName(String username) { | |||||
log.info("多个参数用 @Parameters"); | |||||
return Response.ofSuccess(new User(1, username, "JAVA")); | |||||
} | |||||
@GetMapping("/{id}") | |||||
@Operation(summary = "主键查询(DONE)", description = "备注") | |||||
@Parameters({ | |||||
@Parameter(name = "id", description = "用户编号", in = ParameterIn.PATH, schema = @Schema(implementation = Integer.class), required = true) | |||||
}) | |||||
public Response<User> get(@PathVariable Integer id) { | |||||
log.info("单个参数用 @Parameter"); | |||||
return Response.ofSuccess(new User(id, "u1", "p1")); | |||||
} | |||||
@DeleteMapping("/{id}") | |||||
@Operation(summary = "删除用户(DONE)", description = "备注") | |||||
@Parameter(name = "id", description = "用户编号", in = ParameterIn.PATH, schema = @Schema(implementation = Integer.class), required = true) | |||||
public void delete(@PathVariable Integer id) { | |||||
log.info("单个参数用 Parameter"); | |||||
} | |||||
@PostMapping | |||||
@Operation(summary = "添加用户(DONE)") | |||||
public User post(@RequestBody User user) { | |||||
log.info("如果是 POST PUT 这种带 @RequestBody 的可以不用写 @Parameter"); | |||||
return user; | |||||
} | |||||
@PostMapping("/multipar") | |||||
@Operation(summary = "添加用户(DONE)") | |||||
public List<User> multipar(@RequestBody List<User> user) { | |||||
log.info("如果是 POST PUT 这种带 @RequestBody 的可以不用写 @Parameter"); | |||||
return user; | |||||
} | |||||
@PostMapping("/array") | |||||
@Operation(summary = "添加用户(DONE)") | |||||
public User[] array(@RequestBody User[] user) { | |||||
log.info("如果是 POST PUT 这种带 @RequestBody 的可以不用写 @Parameter"); | |||||
return user; | |||||
} | |||||
@PutMapping("/{id}") | |||||
@Operation(summary = "修改用户(DONE)") | |||||
public void put(@PathVariable Long id, @RequestBody User user) { | |||||
log.info("如果你不想写 @Parameter 那么 swagger 也会使用默认的参数名作为描述信息 "); | |||||
} | |||||
@PostMapping("/{id}/file") | |||||
@Operation(summary = "文件上传(DONE)") | |||||
public String file(@PathVariable Long id, @RequestParam("file") MultipartFile file) { | |||||
log.info(file.getContentType()); | |||||
log.info(file.getName()); | |||||
log.info(file.getOriginalFilename()); | |||||
return file.getOriginalFilename(); | |||||
} | |||||
} | |||||
``` | |||||
### 1.3.编写返回对象 | |||||
```java | |||||
@Data | |||||
@NoArgsConstructor | |||||
@AllArgsConstructor | |||||
@Schema(name = "User", title = "用户实体", description = "User Entity") | |||||
public class User implements Serializable { | |||||
@Serial | |||||
private static final long serialVersionUID = 5057954049311281252L; | |||||
/** | |||||
* 主键id | |||||
*/ | |||||
@Schema(title = "主键id", required = true) | |||||
private Integer id; | |||||
/** | |||||
* 用户名 | |||||
*/ | |||||
@Schema(title = "用户名", required = true) | |||||
private String name; | |||||
/** | |||||
* 工作岗位 | |||||
*/ | |||||
@Schema(title = "工作岗位", required = true) | |||||
private String job; | |||||
} | |||||
``` | |||||
### 1.4.配置 Springdoc | |||||
- **SpringdocAutoConfiguration** | |||||
```java | |||||
@Configuration(proxyBeanMethods = false) | |||||
@OpenAPIDefinition(info = @Info(title = "spring-boot-demo-apidoc-swagger", version = "1.0.0-SNAPSHOT", description = "这是一个简单的 Swagger API 演示", contact = @Contact(name = "Yangkai.Shen", url = "https://xkcoding.com", email = "237497819@qq.com")), | |||||
externalDocs = @ExternalDocumentation(description = "springdoc官方文档", url = "https://springdoc.org/"), | |||||
servers = @Server(url = "http://localhost:8080/demo") | |||||
) | |||||
public class SpringdocAutoConfiguration implements WebMvcConfigurer { | |||||
} | |||||
``` | |||||
- **application.yml** | |||||
```yaml | |||||
server: | |||||
port: 8080 | |||||
servlet: | |||||
context-path: /demo | |||||
springdoc: | |||||
swagger-ui: | |||||
path: /swagger-ui.html | |||||
packages-to-scan: com.xkcoding.swagger.controller | |||||
``` | |||||
## 2.测试 | |||||
启动项目,访问地址:http://localhost:8080/demo/swagger-ui/index.html | |||||
## 3.参考 | |||||
- [Springdoc 官方文档](https://springdoc.org/) | |||||
- [Springfox 迁移到 Springdoc 步骤](https://springdoc.org/#migrating-from-springfox) |
@@ -0,0 +1,64 @@ | |||||
<?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>com.xkcoding</groupId> | |||||
<artifactId>demo-apidoc</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
</parent> | |||||
<modelVersion>4.0.0</modelVersion> | |||||
<artifactId>demo-apidoc-springdoc</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
<packaging>jar</packaging> | |||||
<name>${project.artifactId}</name> | |||||
<description>Demo project for Spring Boot</description> | |||||
<properties> | |||||
<java.version>17</java.version> | |||||
<springdoc.version>2.0.0-M5</springdoc.version> | |||||
</properties> | |||||
<dependencies> | |||||
<dependency> | |||||
<groupId>com.xkcoding</groupId> | |||||
<artifactId>common-tools</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.springdoc</groupId> | |||||
<artifactId>springdoc-openapi-starter-webmvc-ui</artifactId> | |||||
<version>${springdoc.version}</version> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>org.projectlombok</groupId> | |||||
<artifactId>lombok</artifactId> | |||||
<optional>true</optional> | |||||
</dependency> | |||||
</dependencies> | |||||
<build> | |||||
<finalName>${project.artifactId}</finalName> | |||||
<plugins> | |||||
<plugin> | |||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-maven-plugin</artifactId> | |||||
</plugin> | |||||
</plugins> | |||||
</build> | |||||
</project> |
@@ -0,0 +1,20 @@ | |||||
package com.xkcoding.springdoc; | |||||
import org.springframework.boot.SpringApplication; | |||||
import org.springframework.boot.autoconfigure.SpringBootApplication; | |||||
/** | |||||
* <p> | |||||
* 启动器 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2022-09-06 17:04 | |||||
*/ | |||||
@SpringBootApplication | |||||
public class SpringdocApplication { | |||||
public static void main(String[] args) { | |||||
SpringApplication.run(SpringdocApplication.class, args); | |||||
} | |||||
} |
@@ -0,0 +1,26 @@ | |||||
package com.xkcoding.springdoc.config; | |||||
import io.swagger.v3.oas.annotations.ExternalDocumentation; | |||||
import io.swagger.v3.oas.annotations.OpenAPIDefinition; | |||||
import io.swagger.v3.oas.annotations.info.Contact; | |||||
import io.swagger.v3.oas.annotations.info.Info; | |||||
import io.swagger.v3.oas.annotations.servers.Server; | |||||
import org.springframework.context.annotation.Configuration; | |||||
import org.springframework.web.servlet.config.annotation.WebMvcConfigurer; | |||||
/** | |||||
* <p> | |||||
* Springdoc 基础配置 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2022-09-06 22:37 | |||||
*/ | |||||
@Configuration(proxyBeanMethods = false) | |||||
@OpenAPIDefinition(info = @Info(title = "spring-boot-demo-apidoc-swagger", version = "1.0.0-SNAPSHOT", description = "这是一个简单的 Swagger API 演示", contact = @Contact(name = "Yangkai.Shen", url = "https://xkcoding.com", email = "237497819@qq.com")), | |||||
externalDocs = @ExternalDocumentation(description = "springdoc官方文档", url = "https://springdoc.org/"), | |||||
servers = @Server(url = "http://localhost:8080/demo") | |||||
) | |||||
public class SpringdocAutoConfiguration implements WebMvcConfigurer { | |||||
} |
@@ -0,0 +1,90 @@ | |||||
package com.xkcoding.springdoc.controller; | |||||
import com.xkcoding.common.model.viewmodel.Response; | |||||
import com.xkcoding.springdoc.entity.User; | |||||
import io.swagger.v3.oas.annotations.Operation; | |||||
import io.swagger.v3.oas.annotations.Parameter; | |||||
import io.swagger.v3.oas.annotations.Parameters; | |||||
import io.swagger.v3.oas.annotations.enums.ParameterIn; | |||||
import io.swagger.v3.oas.annotations.media.Schema; | |||||
import io.swagger.v3.oas.annotations.tags.Tag; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.web.bind.annotation.*; | |||||
import org.springframework.web.multipart.MultipartFile; | |||||
import java.util.List; | |||||
/** | |||||
* 测试接口 | |||||
* | |||||
* @author 一珩(沈扬凯 yk.shen@tuya.com) | |||||
* @date 2022-09-06 22:36 | |||||
*/ | |||||
@Slf4j | |||||
@RestController | |||||
@RequestMapping("/user") | |||||
@Tag(name = "用户管理", description = "用户管理") | |||||
public class UserController { | |||||
@GetMapping | |||||
@Operation(summary = "条件查询(DONE)", description = "备注") | |||||
@Parameters({ | |||||
@Parameter(name = "username", description = "用户名", in = ParameterIn.QUERY, schema = @Schema(implementation = String.class), required = true) | |||||
}) | |||||
public Response<User> getByUserName(String username) { | |||||
log.info("多个参数用 @Parameters"); | |||||
return Response.ofSuccess(new User(1, username, "JAVA")); | |||||
} | |||||
@GetMapping("/{id}") | |||||
@Operation(summary = "主键查询(DONE)", description = "备注") | |||||
@Parameters({ | |||||
@Parameter(name = "id", description = "用户编号", in = ParameterIn.PATH, schema = @Schema(implementation = Integer.class), required = true) | |||||
}) | |||||
public Response<User> get(@PathVariable Integer id) { | |||||
log.info("单个参数用 @Parameter"); | |||||
return Response.ofSuccess(new User(id, "u1", "p1")); | |||||
} | |||||
@DeleteMapping("/{id}") | |||||
@Operation(summary = "删除用户(DONE)", description = "备注") | |||||
@Parameter(name = "id", description = "用户编号", in = ParameterIn.PATH, schema = @Schema(implementation = Integer.class), required = true) | |||||
public void delete(@PathVariable Integer id) { | |||||
log.info("单个参数用 Parameter"); | |||||
} | |||||
@PostMapping | |||||
@Operation(summary = "添加用户(DONE)") | |||||
public User post(@RequestBody User user) { | |||||
log.info("如果是 POST PUT 这种带 @RequestBody 的可以不用写 @Parameter"); | |||||
return user; | |||||
} | |||||
@PostMapping("/multipar") | |||||
@Operation(summary = "添加用户(DONE)") | |||||
public List<User> multipar(@RequestBody List<User> user) { | |||||
log.info("如果是 POST PUT 这种带 @RequestBody 的可以不用写 @Parameter"); | |||||
return user; | |||||
} | |||||
@PostMapping("/array") | |||||
@Operation(summary = "添加用户(DONE)") | |||||
public User[] array(@RequestBody User[] user) { | |||||
log.info("如果是 POST PUT 这种带 @RequestBody 的可以不用写 @Parameter"); | |||||
return user; | |||||
} | |||||
@PutMapping("/{id}") | |||||
@Operation(summary = "修改用户(DONE)") | |||||
public void put(@PathVariable Long id, @RequestBody User user) { | |||||
log.info("如果你不想写 @Parameter 那么 swagger 也会使用默认的参数名作为描述信息 "); | |||||
} | |||||
@PostMapping("/{id}/file") | |||||
@Operation(summary = "文件上传(DONE)") | |||||
public String file(@PathVariable Long id, @RequestParam("file") MultipartFile file) { | |||||
log.info(file.getContentType()); | |||||
log.info(file.getName()); | |||||
log.info(file.getOriginalFilename()); | |||||
return file.getOriginalFilename(); | |||||
} | |||||
} |
@@ -0,0 +1,41 @@ | |||||
package com.xkcoding.springdoc.entity; | |||||
import io.swagger.v3.oas.annotations.media.Schema; | |||||
import lombok.AllArgsConstructor; | |||||
import lombok.Data; | |||||
import lombok.NoArgsConstructor; | |||||
import java.io.Serial; | |||||
import java.io.Serializable; | |||||
/** | |||||
* <p> | |||||
* 测试用户 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2022-09-06 22:37 | |||||
*/ | |||||
@Data | |||||
@NoArgsConstructor | |||||
@AllArgsConstructor | |||||
@Schema(name = "User", title = "用户实体", description = "User Entity") | |||||
public class User implements Serializable { | |||||
@Serial | |||||
private static final long serialVersionUID = 5057954049311281252L; | |||||
/** | |||||
* 主键id | |||||
*/ | |||||
@Schema(title = "主键id", required = true) | |||||
private Integer id; | |||||
/** | |||||
* 用户名 | |||||
*/ | |||||
@Schema(title = "用户名", required = true) | |||||
private String name; | |||||
/** | |||||
* 工作岗位 | |||||
*/ | |||||
@Schema(title = "工作岗位", required = true) | |||||
private String job; | |||||
} |
@@ -0,0 +1,8 @@ | |||||
server: | |||||
port: 8080 | |||||
servlet: | |||||
context-path: /demo | |||||
springdoc: | |||||
swagger-ui: | |||||
path: /swagger-ui.html | |||||
packages-to-scan: com.xkcoding.swagger.controller |
@@ -0,0 +1,13 @@ | |||||
package com.xkcoding.springdoc; | |||||
import org.junit.jupiter.api.Test; | |||||
import org.springframework.boot.test.context.SpringBootTest; | |||||
@SpringBootTest | |||||
class SpringdocApplicationTests { | |||||
@Test | |||||
void contextLoads() { | |||||
} | |||||
} |
@@ -0,0 +1,24 @@ | |||||
<?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>com.xkcoding</groupId> | |||||
<artifactId>spring-boot-demo</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
</parent> | |||||
<modelVersion>4.0.0</modelVersion> | |||||
<artifactId>demo-apidoc</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
<packaging>pom</packaging> | |||||
<properties> | |||||
<java.version>17</java.version> | |||||
</properties> | |||||
<modules> | |||||
<module>demo-apidoc-springdoc</module> | |||||
</modules> | |||||
</project> |
@@ -1,257 +0,0 @@ | |||||
# spring-boot-demo-async | |||||
> 此 demo 主要演示了 Spring Boot 如何使用原生提供的异步任务支持,实现异步执行任务。 | |||||
## 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-async</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
<packaging>jar</packaging> | |||||
<name>spring-boot-demo-async</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</artifactId> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-starter-test</artifactId> | |||||
<scope>test</scope> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>org.projectlombok</groupId> | |||||
<artifactId>lombok</artifactId> | |||||
<optional>true</optional> | |||||
</dependency> | |||||
</dependencies> | |||||
<build> | |||||
<finalName>spring-boot-demo-async</finalName> | |||||
<plugins> | |||||
<plugin> | |||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-maven-plugin</artifactId> | |||||
</plugin> | |||||
</plugins> | |||||
</build> | |||||
</project> | |||||
``` | |||||
## application.yml | |||||
```yaml | |||||
spring: | |||||
task: | |||||
execution: | |||||
pool: | |||||
# 最大线程数 | |||||
max-size: 16 | |||||
# 核心线程数 | |||||
core-size: 16 | |||||
# 存活时间 | |||||
keep-alive: 10s | |||||
# 队列大小 | |||||
queue-capacity: 100 | |||||
# 是否允许核心线程超时 | |||||
allow-core-thread-timeout: true | |||||
# 线程名称前缀 | |||||
thread-name-prefix: async-task- | |||||
``` | |||||
## SpringBootDemoAsyncApplication.java | |||||
```java | |||||
/** | |||||
* <p> | |||||
* 启动器 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2018-12-29 10:28 | |||||
*/ | |||||
@EnableAsync | |||||
@SpringBootApplication | |||||
public class SpringBootDemoAsyncApplication { | |||||
public static void main(String[] args) { | |||||
SpringApplication.run(SpringBootDemoAsyncApplication.class, args); | |||||
} | |||||
} | |||||
``` | |||||
## TaskFactory.java | |||||
```java | |||||
/** | |||||
* <p> | |||||
* 任务工厂 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2018-12-29 10:37 | |||||
*/ | |||||
@Component | |||||
@Slf4j | |||||
public class TaskFactory { | |||||
/** | |||||
* 模拟5秒的异步任务 | |||||
*/ | |||||
@Async | |||||
public Future<Boolean> asyncTask1() throws InterruptedException { | |||||
doTask("asyncTask1", 5); | |||||
return new AsyncResult<>(Boolean.TRUE); | |||||
} | |||||
/** | |||||
* 模拟2秒的异步任务 | |||||
*/ | |||||
@Async | |||||
public Future<Boolean> asyncTask2() throws InterruptedException { | |||||
doTask("asyncTask2", 2); | |||||
return new AsyncResult<>(Boolean.TRUE); | |||||
} | |||||
/** | |||||
* 模拟3秒的异步任务 | |||||
*/ | |||||
@Async | |||||
public Future<Boolean> asyncTask3() throws InterruptedException { | |||||
doTask("asyncTask3", 3); | |||||
return new AsyncResult<>(Boolean.TRUE); | |||||
} | |||||
/** | |||||
* 模拟5秒的同步任务 | |||||
*/ | |||||
public void task1() throws InterruptedException { | |||||
doTask("task1", 5); | |||||
} | |||||
/** | |||||
* 模拟2秒的同步任务 | |||||
*/ | |||||
public void task2() throws InterruptedException { | |||||
doTask("task2", 2); | |||||
} | |||||
/** | |||||
* 模拟3秒的同步任务 | |||||
*/ | |||||
public void task3() throws InterruptedException { | |||||
doTask("task3", 3); | |||||
} | |||||
private void doTask(String taskName, Integer time) throws InterruptedException { | |||||
log.info("{}开始执行,当前线程名称【{}】", taskName, Thread.currentThread().getName()); | |||||
TimeUnit.SECONDS.sleep(time); | |||||
log.info("{}执行成功,当前线程名称【{}】", taskName, Thread.currentThread().getName()); | |||||
} | |||||
} | |||||
``` | |||||
## TaskFactoryTest.java | |||||
```java | |||||
/** | |||||
* <p> | |||||
* 测试任务 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2018-12-29 10:49 | |||||
*/ | |||||
@Slf4j | |||||
public class TaskFactoryTest extends SpringBootDemoAsyncApplicationTests { | |||||
@Autowired | |||||
private TaskFactory task; | |||||
/** | |||||
* 测试异步任务 | |||||
*/ | |||||
@Test | |||||
public void asyncTaskTest() throws InterruptedException, ExecutionException { | |||||
long start = System.currentTimeMillis(); | |||||
Future<Boolean> asyncTask1 = task.asyncTask1(); | |||||
Future<Boolean> asyncTask2 = task.asyncTask2(); | |||||
Future<Boolean> asyncTask3 = task.asyncTask3(); | |||||
// 调用 get() 阻塞主线程 | |||||
asyncTask1.get(); | |||||
asyncTask2.get(); | |||||
asyncTask3.get(); | |||||
long end = System.currentTimeMillis(); | |||||
log.info("异步任务全部执行结束,总耗时:{} 毫秒", (end - start)); | |||||
} | |||||
/** | |||||
* 测试同步任务 | |||||
*/ | |||||
@Test | |||||
public void taskTest() throws InterruptedException { | |||||
long start = System.currentTimeMillis(); | |||||
task.task1(); | |||||
task.task2(); | |||||
task.task3(); | |||||
long end = System.currentTimeMillis(); | |||||
log.info("同步任务全部执行结束,总耗时:{} 毫秒", (end - start)); | |||||
} | |||||
} | |||||
``` | |||||
## 运行结果 | |||||
### 异步任务 | |||||
```bash | |||||
2018-12-29 10:57:28.511 INFO 3134 --- [ async-task-3] com.xkcoding.async.task.TaskFactory : asyncTask3开始执行,当前线程名称【async-task-3】 | |||||
2018-12-29 10:57:28.511 INFO 3134 --- [ async-task-1] com.xkcoding.async.task.TaskFactory : asyncTask1开始执行,当前线程名称【async-task-1】 | |||||
2018-12-29 10:57:28.511 INFO 3134 --- [ async-task-2] com.xkcoding.async.task.TaskFactory : asyncTask2开始执行,当前线程名称【async-task-2】 | |||||
2018-12-29 10:57:30.514 INFO 3134 --- [ async-task-2] com.xkcoding.async.task.TaskFactory : asyncTask2执行成功,当前线程名称【async-task-2】 | |||||
2018-12-29 10:57:31.516 INFO 3134 --- [ async-task-3] com.xkcoding.async.task.TaskFactory : asyncTask3执行成功,当前线程名称【async-task-3】 | |||||
2018-12-29 10:57:33.517 INFO 3134 --- [ async-task-1] com.xkcoding.async.task.TaskFactory : asyncTask1执行成功,当前线程名称【async-task-1】 | |||||
2018-12-29 10:57:33.517 INFO 3134 --- [ main] com.xkcoding.async.task.TaskFactoryTest : 异步任务全部执行结束,总耗时:5015 毫秒 | |||||
``` | |||||
### 同步任务 | |||||
```bash | |||||
2018-12-29 10:55:49.830 INFO 3079 --- [ main] com.xkcoding.async.task.TaskFactory : task1开始执行,当前线程名称【main】 | |||||
2018-12-29 10:55:54.834 INFO 3079 --- [ main] com.xkcoding.async.task.TaskFactory : task1执行成功,当前线程名称【main】 | |||||
2018-12-29 10:55:54.835 INFO 3079 --- [ main] com.xkcoding.async.task.TaskFactory : task2开始执行,当前线程名称【main】 | |||||
2018-12-29 10:55:56.839 INFO 3079 --- [ main] com.xkcoding.async.task.TaskFactory : task2执行成功,当前线程名称【main】 | |||||
2018-12-29 10:55:56.839 INFO 3079 --- [ main] com.xkcoding.async.task.TaskFactory : task3开始执行,当前线程名称【main】 | |||||
2018-12-29 10:55:59.843 INFO 3079 --- [ main] com.xkcoding.async.task.TaskFactory : task3执行成功,当前线程名称【main】 | |||||
2018-12-29 10:55:59.843 INFO 3079 --- [ main] com.xkcoding.async.task.TaskFactoryTest : 同步任务全部执行结束,总耗时:10023 毫秒 | |||||
``` | |||||
## 参考 | |||||
- Spring Boot 异步任务线程池的配置 参考官方文档:https://docs.spring.io/spring-boot/docs/2.1.0.RELEASE/reference/htmlsingle/#boot-features-task-execution-scheduling |
@@ -1,54 +0,0 @@ | |||||
<?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>demo-async</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
<packaging>jar</packaging> | |||||
<name>demo-async</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</artifactId> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-starter-test</artifactId> | |||||
<scope>test</scope> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>org.projectlombok</groupId> | |||||
<artifactId>lombok</artifactId> | |||||
<optional>true</optional> | |||||
</dependency> | |||||
</dependencies> | |||||
<build> | |||||
<finalName>demo-async</finalName> | |||||
<plugins> | |||||
<plugin> | |||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-maven-plugin</artifactId> | |||||
</plugin> | |||||
</plugins> | |||||
</build> | |||||
</project> |
@@ -1,24 +0,0 @@ | |||||
package com.xkcoding.async; | |||||
import org.springframework.boot.SpringApplication; | |||||
import org.springframework.boot.autoconfigure.SpringBootApplication; | |||||
import org.springframework.scheduling.annotation.EnableAsync; | |||||
/** | |||||
* <p> | |||||
* 启动器 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2018-12-29 10:28 | |||||
*/ | |||||
@EnableAsync | |||||
@SpringBootApplication | |||||
public class SpringBootDemoAsyncApplication { | |||||
public static void main(String[] args) { | |||||
SpringApplication.run(SpringBootDemoAsyncApplication.class, args); | |||||
} | |||||
} | |||||
@@ -1,76 +0,0 @@ | |||||
package com.xkcoding.async.task; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.springframework.scheduling.annotation.Async; | |||||
import org.springframework.scheduling.annotation.AsyncResult; | |||||
import org.springframework.stereotype.Component; | |||||
import java.util.concurrent.Future; | |||||
import java.util.concurrent.TimeUnit; | |||||
/** | |||||
* <p> | |||||
* 任务工厂 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2018-12-29 10:37 | |||||
*/ | |||||
@Component | |||||
@Slf4j | |||||
public class TaskFactory { | |||||
/** | |||||
* 模拟5秒的异步任务 | |||||
*/ | |||||
@Async | |||||
public Future<Boolean> asyncTask1() throws InterruptedException { | |||||
doTask("asyncTask1", 5); | |||||
return new AsyncResult<>(Boolean.TRUE); | |||||
} | |||||
/** | |||||
* 模拟2秒的异步任务 | |||||
*/ | |||||
@Async | |||||
public Future<Boolean> asyncTask2() throws InterruptedException { | |||||
doTask("asyncTask2", 2); | |||||
return new AsyncResult<>(Boolean.TRUE); | |||||
} | |||||
/** | |||||
* 模拟3秒的异步任务 | |||||
*/ | |||||
@Async | |||||
public Future<Boolean> asyncTask3() throws InterruptedException { | |||||
doTask("asyncTask3", 3); | |||||
return new AsyncResult<>(Boolean.TRUE); | |||||
} | |||||
/** | |||||
* 模拟5秒的同步任务 | |||||
*/ | |||||
public void task1() throws InterruptedException { | |||||
doTask("task1", 5); | |||||
} | |||||
/** | |||||
* 模拟2秒的同步任务 | |||||
*/ | |||||
public void task2() throws InterruptedException { | |||||
doTask("task2", 2); | |||||
} | |||||
/** | |||||
* 模拟3秒的同步任务 | |||||
*/ | |||||
public void task3() throws InterruptedException { | |||||
doTask("task3", 3); | |||||
} | |||||
private void doTask(String taskName, Integer time) throws InterruptedException { | |||||
log.info("{}开始执行,当前线程名称【{}】", taskName, Thread.currentThread().getName()); | |||||
TimeUnit.SECONDS.sleep(time); | |||||
log.info("{}执行成功,当前线程名称【{}】", taskName, Thread.currentThread().getName()); | |||||
} | |||||
} |
@@ -1,17 +0,0 @@ | |||||
package com.xkcoding.async; | |||||
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 SpringBootDemoAsyncApplicationTests { | |||||
@Test | |||||
public void contextLoads() { | |||||
} | |||||
} | |||||
@@ -1,56 +0,0 @@ | |||||
package com.xkcoding.async.task; | |||||
import com.xkcoding.async.SpringBootDemoAsyncApplicationTests; | |||||
import lombok.extern.slf4j.Slf4j; | |||||
import org.junit.Test; | |||||
import org.springframework.beans.factory.annotation.Autowired; | |||||
import java.util.concurrent.ExecutionException; | |||||
import java.util.concurrent.Future; | |||||
/** | |||||
* <p> | |||||
* 测试任务 | |||||
* </p> | |||||
* | |||||
* @author yangkai.shen | |||||
* @date Created in 2018-12-29 10:49 | |||||
*/ | |||||
@Slf4j | |||||
public class TaskFactoryTest extends SpringBootDemoAsyncApplicationTests { | |||||
@Autowired | |||||
private TaskFactory task; | |||||
/** | |||||
* 测试异步任务 | |||||
*/ | |||||
@Test | |||||
public void asyncTaskTest() throws InterruptedException, ExecutionException { | |||||
long start = System.currentTimeMillis(); | |||||
Future<Boolean> asyncTask1 = task.asyncTask1(); | |||||
Future<Boolean> asyncTask2 = task.asyncTask2(); | |||||
Future<Boolean> asyncTask3 = task.asyncTask3(); | |||||
// 调用 get() 阻塞主线程 | |||||
asyncTask1.get(); | |||||
asyncTask2.get(); | |||||
asyncTask3.get(); | |||||
long end = System.currentTimeMillis(); | |||||
log.info("异步任务全部执行结束,总耗时:{} 毫秒", (end - start)); | |||||
} | |||||
/** | |||||
* 测试同步任务 | |||||
*/ | |||||
@Test | |||||
public void taskTest() throws InterruptedException { | |||||
long start = System.currentTimeMillis(); | |||||
task.task1(); | |||||
task.task2(); | |||||
task.task3(); | |||||
long end = System.currentTimeMillis(); | |||||
log.info("同步任务全部执行结束,总耗时:{} 毫秒", (end - start)); | |||||
} | |||||
} |
@@ -0,0 +1,83 @@ | |||||
<?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>demo-social</artifactId> | |||||
<version>1.0.0-SNAPSHOT</version> | |||||
<packaging>jar</packaging> | |||||
<name>${project.artifactId}</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> | |||||
<justauth-spring-boot.version>1.1.0</justauth-spring-boot.version> | |||||
</properties> | |||||
<dependencies> | |||||
<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.boot</groupId> | |||||
<artifactId>spring-boot-starter-data-redis</artifactId> | |||||
</dependency> | |||||
<!-- 对象池,使用redis时必须引入 --> | |||||
<dependency> | |||||
<groupId>org.apache.commons</groupId> | |||||
<artifactId>commons-pool2</artifactId> | |||||
</dependency> | |||||
<!-- oauth工具类 --> | |||||
<dependency> | |||||
<groupId>com.xkcoding</groupId> | |||||
<artifactId>justauth-spring-boot-starter</artifactId> | |||||
<version>${justauth-spring-boot.version}</version> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>org.projectlombok</groupId> | |||||
<artifactId>lombok</artifactId> | |||||
<optional>true</optional> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>com.google.guava</groupId> | |||||
<artifactId>guava</artifactId> | |||||
</dependency> | |||||
<dependency> | |||||
<groupId>cn.hutool</groupId> | |||||
<artifactId>hutool-all</artifactId> | |||||
</dependency> | |||||
</dependencies> | |||||
<build> | |||||
<finalName>${project.artifactId}</finalName> | |||||
<plugins> | |||||
<plugin> | |||||
<groupId>org.springframework.boot</groupId> | |||||
<artifactId>spring-boot-maven-plugin</artifactId> | |||||
</plugin> | |||||
</plugins> | |||||
</build> | |||||
</project> |