跪拜 Guibai
← All articles
Backend

Spring Boot 4.2 Lands: RestTemplate Deprecated, Redirect Defaults Flip, and Pulsar Support Ends

By 苏三说技术 ·
Read original on juejin.cn ↗ Google Translate ↗ Alt translation

Upgrading to 4.2 changes runtime behavior without warnings—redirect URLs become relative and X-Forwarded-Prefix is ignored, so proxy-deployed apps can lose path prefixes. Spring Boot 4.1 open-source support ends July 2027, so staying on 4.1 only works until then; deprecations like RestTemplate give time but pile up as technical debt.

Summary

Spring Boot 4.2.0, released November 19, 2026, brings a batch of deprecations that will hit long-standing projects hard. The full RestTemplate infrastructure—auto-configuration, builder, customizers, and TestRestTemplate—is now deprecated, with RestClient and RestTestClient as the replacements. Apache Pulsar support is also deprecated, with 2.0.8 as the final Spring-managed version; future updates come from the Apache Pulsar project itself.

More dangerous than the deprecations are the silent default changes. `server.tomcat.servlet.use-relative-redirects` flips from false to true, so Tomcat now returns relative redirect URLs by default. X-Forwarded-Prefix is ignored by default, which can drop a path prefix for apps behind proxies. These changes produce no warnings—only altered behavior at runtime. A configuration property move from `server.tomcat.*` to `server.tomcat.servlet.*` also carries a deprecated old path.

On the positive side, 4.2 adds native AMQP 1.0 support for RabbitMQ, letting polyglot systems use one standard protocol without custom adapter layers. Executable jar startup gets faster, a direct win for Serverless, FaaS, and Kubernetes scaling. Janino dependency management is removed, so projects using it must declare a version or fail to compile. Spring Boot 4.1.x open source support ends July 31, 2027, putting a hard deadline on the "stay put" strategy.

Takeaways
— RestTemplate and TestRestTemplate are deprecated; use RestClient and RestTestClient respectively.
— Apache Pulsar support in Spring Boot ends with version 2.0.8; future updates come from the Apache Pulsar project's own starter.
— KafkaProperties' buildConsumerProperties(), buildProducerProperties(), and buildAdminProperties() are deprecated in favor of KafkaConfigBuilder.
— server.tomcat.servlet.use-relative-redirects defaults to true, making redirects relative instead of absolute; set it to false to restore old behavior.
— X-Forwarded-Prefix is ignored by default in 4.2; for the framework strategy set spring.webflux.forwarded-headers.use-forwarded-prefix=true, and the universal switch is server.request.header.forwarded.use-prefix=true.
— WebFlux multipart size and count limits are now more explicit; uploads near limits may fail at runtime.
— Janino dependency management is removed from Spring Boot; projects must specify a version or compile fails.
— AMQP 1.0 is now natively supported in Spring Boot, enabling cross-language messaging with RabbitMQ without extra libraries.
— Executable jar startup is faster in 4.2, benefiting Serverless, FaaS, Kubernetes scaling, and CI startup times.
— Spring Boot 4.1.x open source support ends July 31, 2027.
— The migration path for RestTemplate is batch-oriented: migrate new code first, plan legacy code changes.
— The server.tomcat.use-relative-redirects property has moved to server.tomcat.servlet.use-relative-redirects; the old location still works but is deprecated.
Conclusions

Deprecation rather than removal gives projects a safety window, but the silent default changes are the real risk because they alter behavior without any diagnostic output.

Aligning Spring's default with Tomcat's own default is a maintenance choice, yet it forces existing applications to either accept a behavior change or add explicit configuration to opt out.

The X-Forwarded-Prefix change hits a common deployment pattern (multiple proxy layers), so the impact will be underestimated until a path mangling bug surfaces in production.

AMQP 1.0 support arriving after Pulsar's deprecation shows Spring is consolidating around standard protocols while pushing more specialized integrations to their own communities.

The extended 4.1 support window (until July 2027) is a deliberate bridge, but treating it as indefinite is a trap given the cumulative migration burden.

The migration from RestTemplate to RestClient is mostly mechanical, but the scale of existing usage makes it a project-level effort rather than a quick code change.

Concepts & terms
RestClient
The fluent, non-blocking HTTP client introduced in Spring Framework 6.1, designed to replace RestTemplate. It offers a chainable API for request construction, interceptors, and error handling.
AMQP 1.0
An OASIS-standardized messaging protocol that is vendor-agnostic and cross-language. It contrasts with RabbitMQ's proprietary AMQP 0-9-1, allowing polyglot systems to communicate over a single standard protocol.
Source: juejin.cn ↗ Google Translate ↗ Backup ↗