跪拜 Guibai
← All articles
Backend · Java · Spring Boot

Spring Boot 4's Autoconfig Split Silently Breaks Flyway: A Field Guide to Surviving the Dependency Tree Overhaul

By Rain的Java大神之路 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Auto-configuration now fails silently after upgrading to Boot 4, so teams can ship with missing beans and broken database migrations without any error or log. The modularization turns the dependency tree into a contract that must be diffed, gated, and tested before deployment.

Summary

Spring Boot 4 decomposes the 2 MiB spring-boot-autoconfigure jar into dozens of technology-specific modules, moving package paths from org.springframework.boot.autoconfigure.* to org.springframework.boot.<technology>.autoconfigure.*. The upgrade hits hard because startup succeeds without errors, but auto-configurations that rely on conditional class matching simply back off silently. The most common casualty is Flyway: including only flyway-core no longer triggers the Flyway auto-configuration; you must explicitly add spring-boot-starter-flyway. Similar pitfalls include string-based spring.autoconfigure.exclude entries that silently stop matching, a transitive Jackson 3 conflict with legacy com.fasterxml.jackson, and version mediation drifting because the tree's depth changed.

The article details a three-step diagnostic routine: dependency:tree -Dverbose to see which module pulls what, dependency:analyze to catch used-undeclared dependencies, and the --debug condition report (plus /actuator/conditions) to confirm whether a bean was actually created. It then prescribes engineering guards: diff the dependency tree before and after upgrade as a baseline gate, use Enforcer rules (requireUpperBoundDeps, dependencyConvergence, bannedDependencies) to kill version drift and old coordinates, add ArchUnit tests to ban stale package references, and implement a startup self-check that throws if required beans are missing. For custom starter authors, separate the autoconfigure and starter artifacts, use afterName/beforeName string soft references instead of Class literals, and avoid hard compatibility across Boot 3 and 4. The migration roadmap recommends upgrading through 3.5 first, using spring-boot-starter-classic as a transitional crutch, and then trimming modules one by one.

Takeaways
— Boot 4 splits spring-boot-autoconfigure into per-technology modules like spring-boot-webmvc, spring-boot-flyway, and spring-boot-jackson; package paths changed to org.springframework.boot.<technology>.autoconfigure.*.
— Including only flyway-core no longer triggers Flyway auto-configuration; add spring-boot-starter-flyway explicitly.
— String-based spring.autoconfigure.exclude entries silently stop working because package paths moved; use the new package names or drop the starter entirely.
— Jackson 3 (tools.jackson) replaces Jackson 2 (com.fasterxml.jackson); both may coexist via transitive dependencies, causing ClassCastException and serialization inconsistencies.
— Version mediation drifts because tree depth changes; Maven's nearest-wins and Gradle's highest-wins can give different results. Use the spring-boot-dependencies BOM and Enforcer rules (requireUpperBoundDeps, dependencyConvergence).
— Test infrastructure is modularized: @WebMvcTest and other slices require the matching *-test starter; @MockBean is replaced by @MockitoBean; JUnit 4 support is gone.
— Undertow is removed (incompatible with Servlet 6.1); switch to Tomcat 11 or Jetty 12.
— Diagnose with dependency:tree -Dverbose, dependency:analyze, and the --debug condition report (or /actuator/conditions) to verify actual bean creation.
— For custom starters, separate autoconfigure and starter modules, use afterName/beforeName string references for ordering, and avoid hard compatibility with Boot 3.
— Diff the dependency tree before and after upgrade as a baseline gate in CI; use Enforcer and ArchUnit to prevent stale coordinates and old package references.
— Startup self-checks should fail-fast if required beans (e.g., Flyway, transactionManager) are missing, turning silent under-assembly into a deployment-blocking error.
— spring-boot-starter-classic is a transitional crutch that emulates Boot 3 behavior but loses the startup and image size benefits; plan to remove it.
Conclusions

The silent backoff of @ConditionalOnClass means that modularizing auto-configuration turns a library upgrade into a behavior change that only surfaces at runtime, placing the burden on developers to validate bean presence explicitly.

Teams that treat the dependency tree as a diffable and gateable artifact will have a smoother migration; the tree becomes an explicit contract rather than an incidental outcome.

The reliance on string-based excludes and package moves creates a class of bugs that compile fine but break production, so migration work must include scans and architecture tests to catch stale package references.

The split pushes dependency management back to build tools; developers must now declare intent at the starter level rather than enjoying transitive convenience.

Concepts & terms
@ConditionalOnClass
A Spring Boot annotation that activates a configuration class only when a specified class is present on the classpath. In Boot 4, when the matching module isn't included, the condition silently backs off and the feature disappears without errors.
AutoConfiguration.imports
A metadata file under META-INF/spring listing auto-configuration class names. In Boot 4, each module carries its own copy, and incorrect class names cause silent no-assembly when merged via ImportCandidates.
dependency:tree
A Maven plugin target that prints the project's dependency graph. It's used to inspect which modules are brought in and to detect changes like missing transitive dependencies.
Strangler Pattern
A migration strategy where legacy functionality is gradually replaced by new implementations. In Boot 4 migrations, it's used to keep the classic starter temporarily while trimming per-technology starters one by one.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗