Spring Boot 4 把自动配置拆进了很多模块。只升版本号,哪些功能会悄悄消失?要补哪个 starter?这篇用 3.5 的依赖写法在 4.0.8 上逐个验证。
依赖对照:3.5 写法 = starter-web + spring-boot-starter-jdbc + flyway-core + flyway-mysql + mysql-connector-j;4.0 写法 = starter-web + spring-boot-starter-jdbc + spring-boot-starter-flyway + flyway-mysql + mysql-connector-j 3.5.16 + 3.5 写法:表 fw_t 已创建;org.flywaydb.core.Flyway → 有 Bean [flyway] 4.0.8 + 3.5 写法(只换版本):表 fw_t 没有创建;org.flywaydb.core.Flyway → 类在 classpath 上,但容器里没有这个 Bean 4.0.8 + 4.0 的 starter:表 fw_t 已创建;org.flywaydb.core.Flyway → 有 Bean [flyway] 4.0.8 + 4.0 的 starter,但不放 flyway-mysql:启动失败 Caused by: org.flywaydb.core.api.FlywayException: Unsupported Database: MySQL 26.10
只放 flyway-core 在 4.0.8 里迁移静默不执行。
依赖对照:3.5 写法 = starter-web + spring-boot-starter-jdbc + liquibase-core + mysql-connector-j;4.0 写法 = starter-web + spring-boot-starter-jdbc + spring-boot-starter-liquibase + mysql-connector-j 3.5.16 + 3.5 写法:表 lb_t 已创建;liquibase.integration.spring.SpringLiquibase → 有 Bean [liquibase] 4.0.8 + 3.5 写法(只换版本):表 lb_t 没有创建;liquibase.integration.spring.SpringLiquibase → 类在 classpath 上,但容器里没有这个 Bean 4.0.8 + 4.0 的 starter:表 lb_t 已创建;liquibase.integration.spring.SpringLiquibase → 有 Bean [liquibase]
同样静默失效,要加 spring-boot-starter-liquibase。
依赖对照:3.5 写法 = starter-web + spring-boot-starter-aop;4.0 写法 = starter-web + spring-boot-starter-aspectj 3.5.16 + 3.5 写法:GET /hello → hello+advised 4.0.8 + 3.5 写法(只换版本):GET /hello → hello+advised 4.0.8 + 4.0 的 starter:GET /hello → hello+advised
starter-aop 没了,但 aspectjweaver 单放仍生效。
依赖对照:3.5 写法 = starter-web + spring-boot-starter-actuator + micrometer-registry-prometheus;4.0 写法 = starter-web + spring-boot-starter-actuator + micrometer-registry-prometheus + spring-boot-starter-micrometer-metrics 3.5.16 + 3.5 写法:GET /actuator/prometheus → 200;GET /actuator/metrics → 200;io.micrometer.core.instrument.MeterRegistry → 有 Bean [prometheusMeterRegistry] 4.0.8 + 3.5 写法(只换版本):GET /actuator/prometheus → 200;GET /actuator/metrics → 200;io.micrometer.core.instrument.MeterRegistry → 有 Bean [prometheusMeterRegistry] 4.0.8 + 4.0 的 starter:GET /actuator/prometheus → 200;GET /actuator/metrics → 200;io.micrometer.core.instrument.MeterRegistry → 有 Bean [prometheusMeterRegistry]
actuator 加 micrometer-registry-prometheus 在 4.0.8 里照常工作。
依赖对照:3.5 写法 = starter-web + spring-kafka;4.0 写法 = starter-web + spring-boot-starter-kafka 3.5.16 + 3.5 写法:org.springframework.kafka.core.KafkaTemplate → 有 Bean [kafkaTemplate] 4.0.8 + 3.5 写法(只换版本):org.springframework.kafka.core.KafkaTemplate → 类在 classpath 上,但容器里没有这个 Bean 4.0.8 + 4.0 的 starter:org.springframework.kafka.core.KafkaTemplate → 有 Bean [kafkaTemplate]
只放 spring-kafka 在 4.0.8 里没有 KafkaTemplate Bean。
依赖对照:3.5 写法 = starter-web + (无额外依赖);4.0 写法 = starter-web + spring-boot-starter-restclient 3.5.16 + 3.5 写法:org.springframework.web.client.RestClient$Builder → 有 Bean [restClientBuilder] / org.springframework.boot.web.client.RestTemplateBuilder → 有 Bean [restTemplateBuilder] / org.springframework.boot.restclient.RestTemplateBuilder → 类不在 classpath 上 4.0.8 + 3.5 写法(只换版本):org.springframework.web.client.RestClient$Builder → 类在 classpath 上,但容器里没有这个 Bean / org.springframework.boot.web.client.RestTemplateBuilder → 类不在 classpath 上 / org.springframework.boot.restclient.RestTemplateBuilder → 类不在 classpath 上 4.0.8 + 4.0 的 starter:org.springframework.web.client.RestClient$Builder → 有 Bean [restClientBuilder] / org.springframework.boot.web.client.RestTemplateBuilder → 类不在 classpath 上 / org.springframework.boot.restclient.RestTemplateBuilder → 有 Bean [restTemplateBuilder]
starter-web 不再带 RestClient.Builder 的自动配置,RestTemplateBuilder 换了包名。
依赖对照:3.5 写法 = starter-web + spring-webflux;4.0 写法 = starter-web + spring-boot-starter-webclient 3.5.16 + 3.5 写法:org.springframework.web.reactive.function.client.WebClient$Builder → 有 Bean [webClientBuilder] 4.0.8 + 3.5 写法(只换版本):org.springframework.web.reactive.function.client.WebClient$Builder → 类在 classpath 上,但容器里没有这个 Bean 4.0.8 + 4.0 的 starter:org.springframework.web.reactive.function.client.WebClient$Builder → 有 Bean [webClientBuilder]
spring-webflux 单放没有 WebClient.Builder Bean。