build: upgrade all dependencies to latest (Spring Boot 2.5 to 4.1) - #41
Merged
Conversation
将 spring-boot-starter-parent 的伪导入换成 spring-boot-dependencies BOM 导入, 统一由 BOM 管理 spring / jackson / hibernate / junit 等版本。 - spring boot 2.5.12 -> 4.1.1, JDK 11 -> 21 - springfox-swagger 2.2.2 -> springdoc-openapi 3.1.1 (springfox 已停止维护且不支持 jakarta) - mysql:mysql-connector-java 8.0.28 -> com.mysql:mysql-connector-j 26.7.0 (groupId 变更) - dom4j:dom4j 1.6.1 -> org.dom4j:dom4j 2.2.0 (groupId 变更) - com.alibaba:fastjson -> com.alibaba.fastjson2:fastjson2 2.0.65 - poi 3.17 -> 5.5.1, jsoup -> 1.23.2, commons-io -> 2.22.0, commons-lang3 -> 3.20.0 - lombok -> 1.18.48, slf4j -> 2.0.19, zxing -> 3.5.4, mybatis-spring-boot -> 4.1.0 - maven 插件: compiler 3.5.1 -> 3.16.0, surefire 2.19.1 -> 3.6.0, source 3.2.0 -> 3.4.0 同时修掉三个既有问题: - jsoup.version 属性重复定义, 后一处 1.9.2 覆盖了前一处 1.14.2, 导致之前的 jsoup 升级实际未生效 - fastjson 和 commons-fileupload 使用开区间版本 [x,), 构建不可复现, 现已全部钉死 - 移除未被任何代码引用且不兼容 jakarta 的 commons-fileupload, 以及被 spring-boot-starter-test 取代的 junit4 knife4j (swagger-bootstrap-ui 的后继) 最新版 4.5.0 仍锁定 spring boot 3.0.4 与 springdoc 2.x, 无法与 spring boot 4 共存, 故移除, 改用 springdoc 自带的 swagger-ui。
spring boot 3 起 javax.* 全面迁移到 jakarta.*, 同时 spring boot 4 拆分了
autoconfigure 模块并默认改用 jackson 3, 一并适配。
- javax.persistence/servlet/mail/websocket -> jakarta.* (javax.sql / javax.net / javax.swing 属 JDK 自带, 保持不变)
- @EntityScan -> org.springframework.boot.persistence.autoconfigure
- DataSourceAutoConfiguration -> org.springframework.boot.jdbc.autoconfigure
- HibernateJpaAutoConfiguration -> org.springframework.boot.hibernate.autoconfigure
- jackson 2 -> 3: com.fasterxml.jackson.databind.JsonSerializer -> tools.jackson.databind.ValueSerializer,
SerializerProvider -> SerializationContext, serialize 不再抛受检异常
- poi 5: HSSFCell.CELL_TYPE_* 常量 -> CellType 枚举, HSSFDateUtil -> DateUtil
- fastjson -> fastjson2 (JSON / JSONObject 用法一致, 仅换包)
- security: WebSecurityConfigurerAdapter 已被移除, 改用 SecurityFilterChain + UserDetailsService Bean。
内存用户密码补上 {noop} 前缀 —— 原先未指定编码器, 在 spring security 5 之后登录时会直接抛异常
- springfox Docket + ApiInfo -> springdoc GroupedOpenApi + OpenAPI Bean, 保留原有的 basePackage 分组范围
- swagger 注解升级到 OpenAPI 3: @Api -> @tag, @apioperation -> @operation,
@ApiImplicitParam -> @parameter, @ApiModelProperty -> @Schema, @ApiIgnore -> @hidden
- 唯一的测试从 JUnit 4 迁移到 JUnit 5
这些配置编译期不会报错, 但在 spring boot 4 上会静默失效或直接启动失败。 - spring.redis.* -> spring.data.redis.* (spring boot 2.4 起改名) - spring.redis.pool.* -> spring.data.redis.lettuce.pool.* (原写法是 spring boot 1.x 的名字, 早已失效) - org.hibernate.dialect.MySQL5Dialect -> MySQLDialect (MySQL5Dialect 在 hibernate 6 已被移除, 当前为 7.4.5)
- actions/checkout v3 -> v7, github/codeql-action v2 -> v4 (v2 已停止服务) - 新增 actions/setup-java 固定 JDK 21, 不再依赖 runner 镜像的默认 JDK, 否则 spring boot 4 所需的 JDK 17+ 无法保证 - travis: oraclejdk11 -> openjdk21, dist trusty -> jammy - Readme 环境说明与更新日志同步到本次升级
仓库此前没有任何构建 CI: 唯一的 workflow 是 CodeQL(安全扫描), 而 Readme 上的 Travis 徽章指向 travis-ci.org —— 该站 2021 年 6 月已关停, 徽章长期是死链。 也就是说没有任何 CI 会去编译这个项目。 新增 build workflow, 在 JDK 21(编译目标) 和 25(当前 LTS) 上跑 mvn clean install, 并把 Readme 徽章换成该 workflow 的状态。 保留 .travis.yml 未动(本次已同步更新其 jdk 版本), 是否弃用 travis 由仓库主人决定。
该 workflow 自 2022 年加入以来一次都没运行过, 加上 workflow_dispatch 便于手动验证和排查。
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Upgrades every dependency in the project to its latest release. This is not a version-number bump — Spring Boot 2.5.12 to 4.1.1 crosses two major versions, so it carries the full
javaxtojakartamigration, the Jackson 2 to 3 switch, and the removal of several libraries that have no Spring Boot 4 successor.Dependency versions
mysql:mysql-connector-java8.0.28com.mysql:mysql-connector-j26.7.0dom4j:dom4j1.6.1org.dom4j:dom4j2.2.0com.alibaba:fastjson[1.2.31,)com.alibaba.fastjson2:fastjson22.0.65Jackson, Hibernate, JUnit, Tomcat, Thymeleaf and the rest are now managed by the
spring-boot-dependenciesBOM rather than being pinned by hand.Pre-existing bugs fixed along the way
jsoup.versionwas declared twice in the parent POM. The second declaration (1.9.2) silently overrode the first (1.14.2), so Bump jsoup from 1.10.1 to 1.14.2 #32's jsoup upgrade never actually took effect — the build has been resolving a 2016 release this whole time.fastjsonused[1.2.31,)andcommons-fileuploadused[1.3.3,), which makes builds non-reproducible and silently pulls whatever is newest at build time. Both are gone now.spring.redis.pool.*had been dead config since Spring Boot 2.0. The correct key isspring.data.redis.lettuce.pool.*; the old keys were being ignored entirely..password("test")with noPasswordEncoderthrowsIllegalArgumentException: There is no PasswordEncoder mapped for the id "null"on any Spring Security 5+ login attempt. Now{noop}test, which preserves the plaintext-demo intent and actually works.Migration details
javaxtojakarta— 49 imports acrosspersistence,servlet,mailandwebsocket.javax.sql,javax.netandjavax.swingare JDK packages and were correctly left alone.Spring Boot 4 module split —
@EntityScan,DataSourceAutoConfigurationandHibernateJpaAutoConfigurationall moved out oforg.springframework.boot.autoconfigure.*into their own modules.Jackson 2 to 3 — Spring Boot 4 defaults to Jackson 3 under the
tools.jacksonpackage.JsonSerializerbecameValueSerializer,SerializerProviderbecameSerializationContext, andserializeno longer declares a checked exception. Jackson 2.21.5 is still on the classpath because swagger-core needs it; both are BOM-managed and coexist by design.Spring Security —
WebSecurityConfigurerAdapterwas removed in Spring Security 6. Replaced with aSecurityFilterChainbean plus aUserDetailsServicebean.springfox to springdoc — springfox has been unmaintained since 2020 and does not support jakarta. The four
Docket+ApiInfoconfigurations becameGroupedOpenApi+OpenAPIbeans, preserving the originalbasePackagegrouping. 32 annotation usages moved to OpenAPI 3:@Apito@Tag,@ApiOperationto@Operation,@ApiImplicitParamto@Parameter,@ApiModelPropertyto@Schema,@ApiIgnoreto@Hidden.Apache POI 5 — the
HSSFCell.CELL_TYPE_*int constants became theCellTypeenum, andHSSFDateUtilwas folded intoDateUtil.Dropped
knife4j (formerly swagger-bootstrap-ui). Its latest release, 4.5.0, still targets Spring Boot 3.0.4 and springdoc 2.x, so it cannot run under Spring Boot 4. The
/doc.htmlUI it provided is gone; springdoc's own Swagger UI at/swagger-ui.htmlremains and is verified working below.commons-fileupload. Not referenced by any source file, and it is built on
javax.servletwith no drop-in jakarta replacement under the same coordinates.junit4. Superseded by JUnit 5 via
spring-boot-starter-test. The project's single test was migrated.Verification
mvn clean install— all 17 modules pass:Runtime smoke test on the
ordermodule (the one module needing no external services), confirming the springdoc rewiring actually works rather than merely compiling:GET /v3/api-docs/orderreturns a well-formed OpenAPI 3.1.0 document with the migrated annotations intact — tag, summary, description, the path parameter with its description andrequiredflag, and both declared error responses.@Hiddencorrectly keeps the/redirect out of the spec.GET /swagger-ui.htmlreturns 302 to/swagger-ui/index.html, which returns 200.Note
Tests remain globally disabled by
<skipTests>true</skipTests>in the parent POM, unchanged from before. The single existing test (RabbitMqTests) has no@SpringBootTest, so its@Autowiredfield is null and it would NPE if ever enabled — pre-existing, left alone as out of scope here.Security alerts closed
All 7 open Dependabot alerts on the default branch are resolved by this upgrade:
The two jsoup entries are worth calling out: #32 bumped jsoup to 1.14.2 and was merged, but the duplicate
jsoup.versionproperty meant the build kept resolving 1.9.2, so CVE-2021-37714 was never actually fixed. Removing the duplicate is what closes it.