Spring Boot 4.2 Migration Guide: RestTemplate, TestRestTemplate, and Pulsar Deprecations
Spring Boot 4.2.0 introduces useful new features, but it also deprecates several APIs that many Java teams still use in production. The most important migration areas are RestTemplate, TestRestTemplate, and Apache Pulsar support.
This Spring Boot 4.2 migration guide explains what changed, why it matters, and how to upgrade safely without breaking existing functionality.
Table of Contents
- Spring Boot 4.2 Migration Overview
- Before You Upgrade
- Migrate RestTemplate to RestClient
- Migrate TestRestTemplate to RestTestClient
- Handle the Apache Pulsar Deprecation
- Review OpenTelemetry Conventions
- Review SSL Bundle Changes
- Test Buildpack and Ubuntu 26.04 Changes
- Production Rollout Checklist
- FAQs
Spring Boot 4.2 Migration Overview
Spring Boot 4.2.0 was released on November 19, 2026. It adds AMQP 1.0 support, opt-in OpenTelemetry semantic conventions, LDAP SSL bundles, registry-backed Buildpack caches, Ubuntu 26.04-based images, and faster executable JAR startup.
The release also deprecates RestTemplate and TestRestTemplate in favor of RestClient and RestTestClient. Apache Pulsar support is deprecated as well, following its move to the Apache Software Foundation.
| Change | Impact | Recommended action |
|---|---|---|
RestTemplate deprecated |
Existing HTTP client code continues to work, but the API is deprecated | Use RestClient for new code and migrate existing clients gradually |
TestRestTemplate deprecated |
Integration tests using the old API are affected | Migrate tests to RestTestClient |
| Apache Pulsar support deprecated | Pulsar-specific Spring Boot integration is deprecated | Follow the official migration guide and move to the new Apache Pulsar support for Spring starter |
| OpenTelemetry conventions opt-in | Existing telemetry names remain unchanged unless enabled | Enable only after validating dashboards and alerts |
| LDAP SSL bundles added | LDAP TLS configuration can be simplified | Adopt SSL bundles where LDAP is used |
| Ubuntu 26.04 Buildpack images | Container base image changes for Buildpack builds | Rebuild, scan, and test container images |
Before You Upgrade
Do not treat this as a simple version-number change. A Spring Boot upgrade can affect dependencies, configuration defaults, HTTP clients, tests, observability data, and container images.
Pre-upgrade checklist
- Upgrade to the latest stable Spring Boot 4.1 patch release first, if your project is currently on 4.1.
- Review the official Spring Boot 4.2 release notes and upgrade instructions.
- Check compatibility of third-party starters, security libraries, database drivers, and observability agents.
- Run the complete test suite, including integration and contract tests.
- Search the codebase for deprecated APIs.
- Build and test the Docker or OCI image before deploying.
- Compare startup time, memory usage, and key business metrics in staging.
- Prepare a rollback plan before production deployment.
Find deprecated APIs quickly
Use IDE inspections, compiler warnings, static analysis, and a simple project-wide search:
RestTemplate
TestRestTemplate
Pulsar
spring.pulsar
Also review your dependency tree for libraries that may internally use deprecated Spring APIs.
Migrate RestTemplate to RestClient
RestTemplate has been a common HTTP client in Spring applications for many years. Spring Boot 4.2 deprecates it in favor of RestClient, which provides a modern, fluent API for synchronous HTTP calls.
Spring also deprecates related infrastructure such as RestTemplateBuilder, RestTemplateCustomizer, and the RestTemplate auto-configuration. Applications that build a RestTemplate through the auto-configured builder should move to RestClient.Builder.
Before: RestTemplate example
import org.springframework.http.ResponseEntity;
import org.springframework.web.client.RestTemplate;
@Service
public class UserService {
private final RestTemplate restTemplate = new RestTemplate();
public User getUser(Long id) {
return restTemplate.getForObject(
"https://api.example.com/users/{id}",
User.class,
id
);
}
public ResponseEntity<User> getUserResponse(Long id) {
return restTemplate.getForEntity(
"https://api.example.com/users/{id}",
User.class,
id
);
}
}
After: RestClient example
import org.springframework.web.client.RestClient;
@Service
public class UserService {
private final RestClient restClient;
public UserService(RestClient.Builder builder) {
this.restClient = builder
.baseUrl("https://api.example.com")
.build();
}
public User getUser(Long id) {
return restClient
.get()
.uri("/users/{id}", id)
.retrieve()
.body(User.class);
}
}
POST request example
import org.springframework.http.MediaType;
public User createUser(UserRequest request) {
return restClient
.post()
.uri("/users")
.contentType(MediaType.APPLICATION_JSON)
.body(request)
.retrieve()
.body(User.class);
}
Best practices
- Inject
RestClient.Builderinstead of creating clients manually. - Configure timeouts, retries, and resilience policies at the client or infrastructure level.
- Use typed request and response records or DTOs.
- Avoid leaking internal exception details in API error responses.
- Add integration tests for external API calls.
Migrate TestRestTemplate to RestTestClient
TestRestTemplate is commonly used in Spring Boot integration tests. Spring Boot 4.2 deprecates it in favor of RestTestClient.
You can annotate a test class with @AutoConfigureRestTestClient and inject a RestTestClient. Depending on the test setup, it can use a mock transport or send requests to a live server.
Before: TestRestTemplate example
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.boot.test.web.client.TestRestTemplate;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class UserControllerTest {
@Autowired
private TestRestTemplate restTemplate;
@Test
void shouldReturnUser() {
ResponseEntity<User> response = restTemplate.getForEntity(
"/api/users/1",
User.class
);
assertThat(response.getStatusCode()).isEqualTo(HttpStatus.OK);
assertThat(response.getBody()).isNotNull();
}
}
After: RestTestClient example
import org.springframework.boot.test.autoconfigure.web.reactive.AutoConfigureWebTestClient;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.web.reactive.server.WebTestClient;
import static org.assertj.core.api.Assertions.assertThat;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureWebTestClient
class UserControllerTest {
@Autowired
private WebTestClient webTestClient;
@Test
void shouldReturnUser() {
webTestClient
.get()
.uri("/api/users/1")
.exchange()
.expectStatus().isOk()
.expectBody(User.class)
.consumeWith(result ->
assertThat(result.getResponseBody()).isNotNull()
);
}
}
If your project provides RestTestClient through the Spring Boot 4.2 test support, use it directly:
import org.springframework.boot.test.autoconfigure.web.servlet.AutoConfigureRestTestClient;
import org.springframework.boot.test.web.client.TestRestClient;
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureRestTestClient
class UserControllerTest {
@Autowired
private TestRestClient restTestClient;
@Test
void shouldReturnUser() {
restTestClient
.get()
.uri("/api/users/1")
.exchange()
.expectStatus().isOk()
.expectBody(User.class)
.consumeWith(result ->
assertThat(result.getResponseBody()).isNotNull()
);
}
}
Migration tips
- Migrate tests one controller or module at a time.
- Keep critical regression tests running during the transition.
- Use realistic test data and verify response status, headers, and body structure.
- Test authentication, authorization, validation errors, and error responses explicitly.
Handle the Apache Pulsar Deprecation
Spring Boot 4.2 deprecates Apache Pulsar support, including spring-boot-starter-pulsar. This happens because Spring for Apache Pulsar has moved to the Apache Software Foundation and is now named Apache Pulsar support for Spring.
The final Spring-managed release is Spring for Apache Pulsar 2.0.8. Spring Boot recommends following the official migration guide and moving to the starter provided by the new project.
What to do now
- Identify every Pulsar producer, consumer, configuration property, and test in your codebase.
- Document the business purpose of each Pulsar integration.
- Review the official Apache Pulsar support for Spring migration guide.
- Replace the deprecated Spring Boot Pulsar starter with the new project-supported starter.
- Test producers, consumers, error handling, retries, and dead-letter behavior.
Example migration strategy
If your team uses Pulsar for event publishing, introduce an application-level messaging abstraction before changing the broker integration:
public interface OrderEventPublisher {
void publish(OrderCreatedEvent event);
}
Then implement the interface using the current Pulsar integration. Later, you can introduce an alternative implementation without changing every business service.
@Component
class PulsarOrderEventPublisher implements OrderEventPublisher {
@Override
public void publish(OrderCreatedEvent event) {
// Existing Pulsar publishing logic
}
}
This approach reduces coupling between domain logic and a specific messaging technology.
Review OpenTelemetry Conventions
Spring Boot 4.2 makes OpenTelemetry semantic conventions opt-in. This is helpful because it prevents an upgrade from silently changing telemetry attribute names used by existing dashboards and alerts.
Enable the new conventions
management:
observations:
conventions: open-telemetry
Before enabling in production
- Export traces, metrics, and logs from a staging environment.
- Compare old and new attribute names.
- Update Grafana, Datadog, Splunk, Elasticsearch, or other observability queries.
- Validate service maps, distributed traces, RED metrics, and alert rules.
- Roll out gradually to one service or one environment at a time.
Review SSL Bundle Changes
Spring Boot 4.2 adds SSL bundle support for LDAP, including the embedded LDAP server. If your application uses LDAP authentication or directory integration, this is a good opportunity to simplify TLS configuration.
Example LDAP SSL bundle
spring:
ssl:
bundle:
pem:
ldap:
truststore:
certificate: "classpath:ldap-ca.pem"
ldap:
ssl:
bundle: ldap
Validation checklist
- Confirm that the LDAP server certificate chain is trusted.
- Test certificate expiration and renewal procedures.
- Validate LDAPS connectivity from the application environment.
- Ensure secrets and certificates are managed securely.
- Test authentication and authorization flows after the change.
Test Buildpack and Ubuntu 26.04 Changes
Spring Boot 4.2 changes the default Buildpack builder to an Ubuntu 26.04-based image. This affects applications that build OCI images through the Spring Boot Maven or Gradle plugin.
What to validate
- Application startup in the new container image.
- JVM behavior and memory settings.
- Timezone, locale, and character-encoding behavior.
- File permissions and writable directories.
- Native libraries or OS-level dependencies.
- Health checks, graceful shutdown, and container orchestration behavior.
Build an image with Maven
./mvnw spring-boot:build-image
Build an image with Gradle
./gradlew bootBuildImage
Run the resulting image locally and in staging before relying on it in production.
Production Rollout Checklist
- Upgrade a non-critical service first.
- Run automated tests, including integration and contract tests.
- Build and scan the new container image.
- Deploy to staging and compare startup and runtime metrics.
- Validate observability dashboards and alerts.
- Use a canary or blue-green deployment strategy.
- Monitor error rates, latency, memory, CPU, GC behavior, and business KPIs.
- Keep the previous version available for a fast rollback.
FAQs
Is RestTemplate removed in Spring Boot 4.2?
No. RestTemplate is deprecated, not removed. Existing code can continue to work, but new code should use RestClient.
Is TestRestTemplate removed in Spring Boot 4.2?
No. TestRestTemplate is deprecated in favor of RestTestClient. Existing tests should continue to work, but migration is recommended.
Does the Pulsar deprecation break my application?
Not immediately. Deprecation is a warning that the integration is no longer the preferred long-term approach. You should create a migration plan and monitor future Spring Boot releases.
Can I upgrade directly from Spring Boot 3.x to 4.2?
You may be able to, but it is safer to review all changes introduced between Spring Boot 3.x and 4.2. Major-version upgrades can include dependency, configuration, and API changes.
Should I enable OpenTelemetry semantic conventions immediately?
Not necessarily. Enable them after testing how they affect your observability dashboards, alerts, and saved queries.
What is the biggest risk in a Spring Boot 4.2 upgrade?
The biggest risks are usually third-party compatibility, changed container base images, observability attribute changes, and untested integrations. A staged rollout reduces these risks.
Final Thoughts
The Spring Boot 4.2 migration is manageable if you approach it systematically. Start with a compatibility assessment, migrate deprecated HTTP client APIs incrementally, test container images, and validate observability before production rollout.
For most teams, the best approach is to upgrade one service at a time, automate regression testing, and keep the previous version available until the new release is stable in production.
Next in this series: AMQP 1.0 Support in Spring Boot 4.2: Generic Messaging and RabbitMQ
Comments
Post a Comment