11[ ![ Build] ( https://github.com/houko/SpringBootUnity/actions/workflows/build.yml/badge.svg?branch=main )] ( https://github.com/houko/SpringBootUnity/actions/workflows/build.yml )
2- [ ![ Backers on Open Collective] ( https://opencollective.com/SpringBootUnity/backers/badge.svg )] ( #backers ) [ ![ Sponsors on Open Collective] ( https://opencollective.com/SpringBootUnity/sponsors/badge.svg )] ( #sponsors ) [ ![ GitHub issues] ( https://img.shields.io/github/issues/houko/SpringBootUnity.svg )] ( https://github.com/houko/SpringBootUnity/issues )
3- [ ![ GitHub license] ( https://img.shields.io/badge/license-MIT-blue.svg )] ( https://raw.githubusercontent.com/houko/SpringBootUnity/main/LICENSE )
4- [ ![ Maven Central] ( https://img.shields.io/maven-central/v/org.apache.maven/apache-maven.svg )] ( )
2+ [ ![ CodeQL] ( https://github.com/houko/SpringBootUnity/actions/workflows/codeql-analysis.yml/badge.svg?branch=main )] ( https://github.com/houko/SpringBootUnity/actions/workflows/codeql-analysis.yml )
3+ [ ![ GitHub license] ( https://img.shields.io/badge/license-MIT-blue.svg )] ( LICENSE )
4+ [ ![ Spring Boot] ( https://img.shields.io/badge/spring%20boot-4.1.1-brightgreen.svg )] ( https://spring.io/projects/spring-boot )
5+ [ ![ JDK] ( https://img.shields.io/badge/JDK-21%2B-orange.svg )] ( https://adoptium.net/ )
6+ [ ![ GitHub issues] ( https://img.shields.io/github/issues/houko/SpringBootUnity.svg )] ( https://github.com/houko/SpringBootUnity/issues )
7+ [ ![ Backers on Open Collective] ( https://opencollective.com/SpringBootUnity/backers/badge.svg )] ( #支持者 ) [ ![ Sponsors on Open Collective] ( https://opencollective.com/SpringBootUnity/sponsors/badge.svg )] ( #赞助商 )
8+
9+ # SpringBootUnity
510
6- ### 项目简介
711![ mark] ( screenshot/SpringBootUnity.png )
812
9- ### 环境
10- - ` maven ` latest
11- - ` jdk21 `
12- - ` spring boot 4.x release `
13- - 个人推荐` idea ` 来代替eclipse
14- - git: 版本管理
15- - nginx: 反向代理服务器
13+ ## 项目简介
1614
15+ 需求是多变的。本项目以 Spring Boot 为基础,针对不同需求把不同的技术和 Spring Boot 搭配起来,每一种搭配单独做成一个模块,因此它是一个偏使用示例的集合而非一个完整产品。
1716
18- ### 注意事项
19- - 本项目代码托管在[ github] ( https://github.com/houko/SpringBootUnity ) 和[ 码云] ( http://git.oschina.net/hupeng_admin/SpringBootUnity ) 两个地方,最新代码会先推送在github上,码云上会在github上更新完之后进行同步。
20- - 本项目多数数据库都用到了` hibernate ` ,如果没有提供` sql ` 文件。则启动时会根据代码映射自动生成数据库表,请在启动前修改` application.properties ` 中的数据库连接信息
17+ 每个模块都能独立打包、独立启动,互不影响,可以只挑自己关心的那一个跑起来看。如果你在使用 Spring Boot 的过程中有什么好用的技术,欢迎提 PR。
2118
19+ ## 模块一览
2220
23- ### 启动方式
21+ 一共 16 个模块。 ` core ` 是被其他模块共同依赖的基础包,其余每个模块各自演示一项技术。
2422
25- - 本地运行
26- 本repo是一个多模块组成,每一个模块都可以单独打包运行。如果想运行哪个模块可以找到对应的Main文件右键运行。
27- ![ run] ( screenshot/run.png )
23+ | 模块 | 演示内容 | 启动类 | 需要的外部服务 |
24+ | --- | --- | --- | --- |
25+ | ` core ` | 公共基础包:工具类、基类、常量、异常、过滤器。被所有模块依赖,** 不可独立运行** | — | — |
26+ | ` website ` | 个人站点:JPA + FreeMarker 页面 + OpenAPI 接口,模块中最完整的一个 | ` XiaomoMain ` | MySQL、Redis |
27+ | ` javase ` | Java SE 题库接口,JPA + OpenAPI 的典型增删改查 | ` QuestionMain ` | MySQL |
28+ | ` order ` | 订单接口,含 zxing 二维码生成 | ` OrderMain ` | — |
29+ | ` mongodb ` | MongoDB 文档数据库读写 | ` MongodbMain ` | MongoDB |
30+ | ` mybatis ` | MyBatis 替代 JPA 作为持久层 | ` MybatisMain ` | MySQL |
31+ | ` multipleSource ` | 多数据源配置与切换 | ` MultipleSourceMain ` | MySQL ×2 |
32+ | ` redis ` | Redis 缓存读写与定时刷新 | ` RedisMain ` | Redis |
33+ | ` rabbitmq ` | RabbitMQ 消息收发 | ` RabbitMqMain ` | RabbitMQ |
34+ | ` security ` | Spring Security 表单登录与鉴权 | ` SecurityMain ` | — |
35+ | ` socket ` | WebSocket 在线聊天,端口 ** 8081** | ` ChatMain ` | — |
36+ | ` scheduled ` | ` @Scheduled ` 定时任务 | ` ScheduledMain ` | — |
37+ | ` async ` | ` @Async ` 异步任务 | ` AsyncMain ` | — |
38+ | ` crawler ` | jsoup 网络爬虫(阴阳师式神数据),抓取后落库 | ` CrawlerMain ` | MySQL |
39+ | ` freemarker ` | FreeMarker 模板引擎 | ` FreemarkerMain ` | — |
40+ | ` thymeleaf ` | Thymeleaf 模板引擎 | ` ThymeleafMain ` | — |
41+
42+ 除 ` socket ` 使用 8081 外,其余模块都监听 ** 8080** ,所以一次只启动一个模块。
43+
44+ ## 技术栈
45+
46+ | 组件 | 版本 |
47+ | --- | --- |
48+ | Spring Boot | 4.1.1 |
49+ | JDK | 21(编译目标;CI 同时在 21 和 25 上构建) |
50+ | Maven | 3.9+ |
51+ | Hibernate / Spring Data JPA | 7.x |
52+ | Jackson | 3.x |
53+ | API 文档 | springdoc-openapi 3.x(OpenAPI 3.1) |
54+ | 数据库驱动 | MySQL Connector/J |
55+ | 其他 | MyBatis、Lettuce(Redis)、jsoup、Apache POI、fastjson2、zxing |
2856
57+ Spring、Jackson、Hibernate、JUnit 等版本统一由 ` spring-boot-dependencies ` BOM 管理,不在本项目中单独指定。
2958
30- - 在linux服务器运行
31- ` spring boot ` 内置了tomcat做为web容器,默认打成jar包直接放在服务器上执行就可以了
32- > ` java -Xms64m -Xmx2048m -jar project.jar 5 >> ./project.log & `
59+ ## 环境要求
3360
61+ - JDK 21 或更高(Spring Boot 4 的最低要求是 17)
62+ - Maven 3.9 或更高
63+ - 按需准备对应模块的外部服务(见上表),只跑不需要外部服务的模块则无需任何准备
3464
65+ ## 快速开始
3566
36- ### 打包
37- - 如果需要定制化打成war包,那么也很简单。在` maven ` 中做下设置就ok了,然后把war包扔到tomcat下面就可以运行了
67+ 构建全部模块:
3868
69+ ``` bash
70+ mvn clean install
3971```
40- <modelVersion>4.0.0</modelVersion>
41- <artifactId>api</artifactId>
42- <packaging>war</packaging>
72+
73+ 启动某一个模块,例如不依赖任何外部服务的 ` order ` :
74+
75+ ``` bash
76+ java -jar order/target/order-2020.1.jar
4377```
4478
79+ 也可以用 Maven 直接跑:
80+
81+ ``` bash
82+ mvn spring-boot:run -pl order
83+ ```
84+
85+ 在 IDE 中则找到对应模块的 ` *Main ` 类直接运行即可。
86+
87+ ![ run] ( screenshot/run.png )
88+
89+ 部署到服务器时,Spring Boot 内置了 Tomcat,把打好的 jar 传上去执行就可以:
90+
91+ ``` bash
92+ java -Xms64m -Xmx2048m -jar order-2020.1.jar >> ./order.log 2>&1 &
93+ ```
94+
95+ ## API 文档
96+
97+ 带有 OpenAPI 注解的模块(` website ` 、` javase ` 、` order ` 、` mongodb ` )启动后可访问:
4598
46- ### 更新日志
47- - 2017-09-02 api模块: 添加swagger-bootstrap-ui,和原有ui并行存在。
48- http://localhost:8080 默认UI
49- http://localhost:808/doc.html bootstrap-ui
50-
51- - 2017-09-02 spring boot版本从1.4.3更新到1.5.8
52- - 2017-09-02 修复不配置数据库信息无法启动的bug
53- - 2017-09-02 版本号更新到2017.1
54- - 2017-09-02 api模块(swagger)添加开源库swagger-bootstrap-ui,和swagger默认UI同时存在。
55- - 2017-09-02 web模块添加数据库sql文件,导入后一键启动可直接访问到web界面。
56- - 2017-09-06 mybatis模块:添加USER.sql,启动后访问:http://localhost:8080 即可看到接口数据
57- - 2017-09-06 所有模块: 添加 characterEncoding=utf8&useSSL=true 解决高版本mysql的sll警告
58- - 2017-09-06 添加代码贡献者列表和支持者,赞助商链接。
59- - 2017-09-08 crawler模块(网络爬虫):修复本地文件目录不存在会报错的bug。处理方式为:不存在则自动创建
60- - 2017-11-02 开源协议从apache更换到MIT
61- - 2017-11-02 添加本地运行方式的说明
62- - 2017-11-02 版本更新到2020.1
63- - 2017-11-02 spring boot版本更新到1.5.8
64- - 2017-11-03 添加kotlin环境配置
65- - 2017-11-03 按照阿里巴巴编程规范插件P3C优化代码
66- - 2017-11-03 合并` api ` 和` website ` 模块,访问` localhost:8080 ` 会显示网站主页,访问` localhost:8080/api ` 会显示api管理界面
67- - 2018-04-09 将整个项目升级到spring boot2.0 release版本,api有较大变动
68- - 2019-08-06 travis-ci指定jdk版本
69- - 2020-10-09 升级版本到2020.2
70- - 2020-10-09 升级jdk版本到11
71- - 2020-10-09 升级mysql connector到8
72- - 2020-10-09 升级spring boot到2.3.0
73- - 2020-10-09 修复了升级后API的破坏性变动,修复了一些了编辑器警告
74- - 2026-09-09 升级spring boot到4.1.1,jdk升级到21,全部依赖更新到最新版本
75- - 2026-09-09 ` javax.* ` 迁移到 ` jakarta.* ` (persistence/servlet/mail/websocket)
76- - 2026-09-09 api文档从已停止维护的springfox迁移到springdoc-openapi,swagger注解升级到OpenAPI 3
77- - 2026-09-09 security模块改用SecurityFilterChain组件式配置,替换已移除的WebSecurityConfigurerAdapter
78- - 2026-09-09 fastjson迁移到fastjson2,jackson升级到3.x,poi升级到5.x,dom4j迁移到org.dom4j
99+ - Swagger UI:< http://localhost:8080/swagger-ui.html >
100+ - OpenAPI 描述文档:< http://localhost:8080/v3/api-docs >
79101
102+ ![ swagger] ( screenshot/swagger-ui.png )
80103
104+ ## 配置说明
81105
106+ 每个模块的配置在各自的 ` src/main/resources/config/application.properties ` ,日志配置在同目录的 ` logback-dev.xml ` 。
107+
108+ 需要注意:
109+
110+ - 涉及数据库的模块请先修改 ` spring.datasource.* ` 中的连接信息。多数模块使用 Hibernate 的 ` ddl-auto=update ` ,在没有提供 sql 文件时会依据实体类映射自动建表。
111+ - 仓库里的账号密码全部是占位符,** 不要把真实凭据提交进版本库** 。` core/src/main/resources/config/oauth.properties ` 中的第三方登录密钥同理,请填入自己申请的值,或改为从环境变量注入。
112+
113+ ## 打包成 war
114+
115+ 如果需要部署到外部 Tomcat,在对应模块的 ` pom.xml ` 中改打包方式即可:
116+
117+ ``` xml
118+ <packaging >war</packaging >
119+ ```
120+
121+ ## 更新日志
122+
123+ 完整记录见 [ changeLog.md] ( changeLog.md ) ,以下为主要节点:
124+
125+ - ** 2026-09-09** 升级到 Spring Boot 4.1.1、JDK 21,全部依赖更新到最新版本;` javax.* ` 迁移到 ` jakarta.* ` ;API 文档从已停止维护的 springfox 迁移到 springdoc-openapi;security 模块改用 ` SecurityFilterChain ` 组件式配置;fastjson 迁移到 fastjson2,Jackson 升级到 3.x,POI 升级到 5.x;新增 GitHub Actions 构建 CI
126+ - ** 2020-10-09** 升级到 Spring Boot 2.3.0、JDK 11,MySQL Connector 升级到 8
127+ - ** 2018-04-09** 升级到 Spring Boot 2.0 release,API 有较大变动
128+ - ** 2017-11-03** 合并 ` api ` 和 ` website ` 模块;按阿里巴巴编程规范 P3C 优化代码
129+ - ** 2017-11-02** 开源协议从 Apache 更换为 MIT
130+ - ** 2017-09-08** crawler 模块修复本地目录不存在时报错的问题
131+
132+ ## 项目状态
133+
134+ 本项目定位是示例集合,模块按需增删。欢迎通过 [ issue] ( https://github.com/houko/SpringBootUnity/issues ) 反馈问题或提出想看到的技术搭配。
135+
136+ 本项目同时托管在 [ GitHub] ( https://github.com/houko/SpringBootUnity ) 和 [ Gitee] ( https://gitee.com/hupeng_admin/SpringBootUnity ) ,以 GitHub 为准。
82137
83138## 贡献者
84139
85140感谢所有为本项目做出贡献的开发者们.
86- <a href =" graphs/contributors " ><img src =" https://opencollective.com/SpringBootUnity/contributors.svg?width=890 " /></a >
87141
142+ <a href =" https://github.com/houko/SpringBootUnity/graphs/contributors " ><img src =" https://opencollective.com/SpringBootUnity/contributors.svg?width=890 " /></a >
88143
89144## 支持者
90145
91146感谢您的支持! 🙏 [[ 成为支持者] ( https://opencollective.com/SpringBootUnity#backer )]
92147
93148<a href =" https://opencollective.com/SpringBootUnity#backers " target =" _blank " ><img src =" https://opencollective.com/SpringBootUnity/backers.svg?width=890 " ></a >
94149
95-
96150## 赞助商
97151
98- [[ 成为赞助商] ( https://opencollective.com/SpringBootUnity#sponsor )] 支持本项目并成为赞助商. 您的LOGO和网站链接将会被展示在这里.
152+ [[ 成为赞助商] ( https://opencollective.com/SpringBootUnity#sponsor )] 支持本项目并成为赞助商. 您的 LOGO 和网站链接将会被展示在这里.
99153
100154<a href =" https://opencollective.com/SpringBootUnity/sponsor/0/website " target =" _blank " ><img src =" https://opencollective.com/SpringBootUnity/sponsor/0/avatar.svg " ></a >
101155<a href =" https://opencollective.com/SpringBootUnity/sponsor/1/website " target =" _blank " ><img src =" https://opencollective.com/SpringBootUnity/sponsor/1/avatar.svg " ></a >
@@ -108,47 +162,22 @@ http://localhost:808/doc.html bootstrap-ui
108162<a href =" https://opencollective.com/SpringBootUnity/sponsor/8/website " target =" _blank " ><img src =" https://opencollective.com/SpringBootUnity/sponsor/8/avatar.svg " ></a >
109163<a href =" https://opencollective.com/SpringBootUnity/sponsor/9/website " target =" _blank " ><img src =" https://opencollective.com/SpringBootUnity/sponsor/9/avatar.svg " ></a >
110164
111- ### 项目说明
112- 需求是多变的,本项目是以spring boot为基础,在使用spring boot的过程中对应不同的需求选用不同的技术和spring boot进行搭配,因此本项目是个偏于使用示例的定位。同时如果您在使用spring boot的过程中有什么好用的技术期待您对本项目的PR。
113-
114- ### 关于我
115- @[ 小莫] ( https://xiaomo.info ) :本人是一个热爱开源精神、追求新潮的开发者,技术过得去,还算勤勉!习惯以github的issue驱动方式来组织我的项目,也希望感兴趣的朋友和我联系,一起进步,共同开发感兴趣的开源项目。目前任rpg服务端主程,熟悉游戏开发和web开发。同时也是个喜欢二次元的死宅,爱动漫,略懂日语。
116-
117- ### 在线小工具
118-
119- - [ 在线Cron表达式生成器] ( http://cron.qqe2.com/ " 在线Cron表达式生成器 ")
165+ ## 关于我
120166
121- - [ 在线工具 - 程序员的工具箱] ( http://tool.lu/ " 在线工具 - 程序员的工具箱 ")
122- - [ spring boot官方脚手架] ( https://start.spring.io/ " spring boot官方脚手架 ")
167+ @[ 小莫] ( https://xiaomo.info ) :热爱开源、追求新潮的开发者,习惯以 GitHub 的 issue 驱动方式组织自己的项目。熟悉游戏开发和 Web 开发,目前任 RPG 服务端主程。也是个喜欢二次元的死宅,爱动漫,略懂日语。
123168
169+ 欢迎联系一起进步:
124170
125- ### 问题反馈
126- 1 . 欢迎提[ issue] ( https://github.com/houko/SpringBootUnity/issues ) 一起完善这个项目。
127- 2 . QQ: 83387856
128- 4 . 个人主站: https://xiaomo.info
171+ - Issue:< https://github.com/houko/SpringBootUnity/issues >
172+ - 个人主站:< https://xiaomo.info >
173+ - QQ:83387856
129174
175+ ## 相关链接
130176
131- ## [ License] ( LICENSE " MIT ")
177+ - [ Spring Boot 官方脚手架] ( https://start.spring.io/ )
178+ - [ Spring Boot 官方文档] ( https://docs.spring.io/spring-boot/index.html )
179+ - [ 在线 Cron 表达式生成器] ( https://cron.qqe2.com/ )
132180
133- MIT License
134-
135- Copyright (c) 2022 Peng Hu
136-
137- Permission is hereby granted, free of charge, to any person obtaining a copy
138- of this software and associated documentation files (the "Software"), to deal
139- in the Software without restriction, including without limitation the rights
140- to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
141- copies of the Software, and to permit persons to whom the Software is
142- furnished to do so, subject to the following conditions:
143-
144- The above copyright notice and this permission notice shall be included in all
145- copies or substantial portions of the Software.
146-
147- THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
148- IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
149- FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
150- AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
151- LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
152- OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
153- SOFTWARE.
181+ ## License
154182
183+ [ MIT] ( LICENSE ) © Peng Hu
0 commit comments