Spring Boot 4.2 Released: AMQP 1.0, OpenTelemetry, Faster Startup & RestTemplate Deprecation
Spring Boot 4.2 introduces AMQP 1.0 support with generic and RabbitMQ-specific starters, adopts OpenTelemetry semantic conventions for unified observability, adds LDAP SSL Bundle configuration, accelerates executable JAR startup and Buildpacks CI caching via remote cache images, enables @DefaultValue property placeholders, and deprecates RestTemplate in favor of the modern RestClient API.
Reading font
What Is Spring Boot
Spring Boot simplifies Java backend development through convention over configuration. Since its 1.0 release in 2014, it has provided starter dependencies, auto-configuration, embedded servers (Tomcat, Jetty), and production-ready Actuator endpoints. A minimal application requires only a single class annotated with @SpringBootApplication and a main method calling SpringApplication.run.
Starting with version 4.0 (November 2025), Spring Boot moved to Spring Framework 7, adopted a modular codebase, introduced JSpecify null-safety annotations, and requires Java 17 with first-class support for Java 25. Releases follow a six-month cadence (May and November); 4.2 is the third release on this line and upgrades the baseline to Spring Framework 7.1.
High-Level Overview of 4.2 Features
The release spans messaging, observability, security, build performance, runtime performance, API modernization, and deprecations:
Messaging : New AMQP 1.0 support (generic and RabbitMQ-tailored).
Observability : Optional OpenTelemetry semantic conventions, shared OTLP configuration for traces/metrics/logs, customizable MDC trace-id key.
Security : LDAP client and embedded LDAP server now support SSL Bundle for LDAPS.
Build : Buildpacks build cache can be pushed to a container registry; default builder base image upgraded to Ubuntu 26.04.
Performance : Executable JAR startup faster with reduced memory allocation; auto-configuration sorting and DevTools hot reload also improved.
API : @DefaultValue now accepts property placeholders; Caffeine async cache mode, per-template/listener KafkaAdmin, configurable GraphQL HTTP methods, Maven plugin testClasspath parameter, properties migrator fail-fast, SBOM export, TomcatServerCustomizer, Docker Compose enhancements.
Deprecations : RestTemplate, RestTemplateBuilder, RestTemplateCustomizer, TestRestTemplate, and Apache Pulsar support marked for removal.
Ecosystem upgrades accompany the release: Spring Security 7.2, Spring Data 2026.1, Spring Kafka 4.2, Micrometer 1.18, Hibernate 7.4, JUnit Jupiter 6.1. To upgrade, change the parent POM version to 4.2.0.
AMQP 1.0 Support
Previously, Spring Boot's AMQP integration targeted RabbitMQ's AMQP 0.9.1 protocol. AMQP 1.0 is the OASIS/ISO standard implemented by ActiveMQ Artemis, Azure Service Bus, Solace, and RabbitMQ 4.x. Version 4.2 provides two starters:
Generic AMQP 1.0 ( spring-boot-starter-amqp) built on Qpid ProtonJ2, compatible with any AMQP 1.0 broker.
RabbitMQ-specific AMQP 1.0 ( spring-boot-starter-amqp-rabbitmq) with additional RabbitMQ customizations.
Naming change : The artifact spring-boot-starter-amqp now refers to generic AMQP 1.0; the legacy AMQP 0.9 support moves to spring-boot-starter-rabbitmq. A migration diagram in the article illustrates the mapping.
RabbitMQ AMQP 1.0 Example
Dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-amqp-rabbitmq</artifactId>
</dependency>Configuration (note prefix spring.amqp.rabbitmq; username/password have no defaults):
spring:
amqp:
rabbitmq:
host: localhost
port: 5672
username: admin
password: 123456Producer using RabbitAmqpTemplate with asynchronous send callback:
@Service
public class OrderMessageProducer {
private static final Logger log = LoggerFactory.getLogger(OrderMessageProducer.class);
private final RabbitAmqpTemplate rabbitAmqpTemplate;
public OrderMessageProducer(RabbitAmqpTemplate rabbitAmqpTemplate) {
this.rabbitAmqpTemplate = rabbitAmqpTemplate;
}
public void sendOrderCreated(String orderNo) {
rabbitAmqpTemplate.convertAndSend("order.exchange", "order.created", orderNo)
.thenAccept(success -> log.info("订单消息发送结果:{},订单号:{}", success, orderNo));
}
}Consumer with @RabbitListener (unchanged from previous API):
@Component
public class OrderMessageListener {
private static final Logger log = LoggerFactory.getLogger(OrderMessageListener.class);
@RabbitListener(queues = "order.created.queue")
public void onOrderCreated(String orderNo) {
log.info("收到订单创建消息,开始处理订单:{}", orderNo);
}
}Health indicator key for AMQP 1.0 is amqprabbit (coexists with legacy rabbit ); disable via management.health.amqprabbit.enabled=false .
Observability: Embracing OpenTelemetry Semantic Conventions
The article highlights three improvements in the traces/metrics/logs → OTLP → Collector pipeline:
Optional OpenTelemetry semantic conventions : A single switch ( management.observations.conventions: open-telemetry) makes Micrometer emit metric/label names aligned with the official OpenTelemetry specification, eliminating manual mapping layers.
Shared OTLP configuration : Endpoint, compression, and headers defined once under management.opentelemetry.otlp apply to traces, logs, and metrics; HTTP paths /v1/traces, /v1/logs, /v1/metrics are appended automatically.
Customizable MDC trace-id key : Many organizations use trace_id instead of the default traceId; now configurable via management.tracing.mdc.trace-id-key (and span-id-key), with log correlation IDs updated automatically.
Combined configuration example:
management:
observations:
conventions: open-telemetry
opentelemetry:
otlp:
endpoint: http://otel-collector:4318
compression: gzip
headers:
x-api-key: demo-key
tracing:
sampling:
probability: 1.0
mdc:
trace-id-key: trace_id
span-id-key: span_id
baggage:
tag-fields: tenant-idSample controller logging an order query:
@RestController
public class OrderController {
private static final Logger log = LoggerFactory.getLogger(OrderController.class);
@GetMapping("/api/orders/{orderNo}")
public String getOrder(@PathVariable String orderNo) {
log.info("查询订单:{}", orderNo);
return "订单 " + orderNo + " 状态:已支付";
}
}Console output shows the custom trace_id key in MDC:
2026-11-21 16:52:08.317 INFO 18236 --- [demo] [nio-8080-exec-1] [6a1f9c0e2b7d4e8f9a0b1c2d3e4f5a6b-9a0b1c2d3e4f5a6b] c.e.demo.web.OrderController : 查询订单:NO20261121001Enabling OpenTelemetry conventions disables custom metric naming configs like management.observations.http.server.requests.name ; verify dashboards before migrating.
LDAP SSL Bundle Support
Spring Boot 3.1 introduced SSL Bundle for Web, Redis, Kafka, etc. Version 4.2 extends it to LDAP client and embedded LDAP server, removing the need for custom SocketFactory and manual certificate handling.
Configuration using a PKCS12 truststore bundle:
spring:
ssl:
bundle:
jks:
ldap-bundle:
truststore:
location: classpath:ldap-truststore.p12
password: 123456
type: PKCS12
ldap:
urls: ldaps://ldap.example.com:636
base: dc=example,dc=com
username: cn=admin,dc=example,dc=com
password: 123456
ssl:
bundle: ldap-bundleBusiness code uses LdapTemplate unchanged:
@Service
public class LdapUserService {
private final LdapTemplate ldapTemplate;
public LdapUserService(LdapTemplate ldapTemplate) {
this.ldapTemplate = ldapTemplate;
}
public List<String> findDisplayNames(String uid) {
return ldapTemplate.search(
LdapQueryBuilder.query().where("uid").is(uid),
(AttributesMapper<String>) attrs -> (String) attrs.get("cn").get());
}
}Two convenience improvements:
If only JDK default truststore is needed, set spring.ldap.ssl.enabled=true without a bundle.
Embedded LDAP server for tests now supports LDAPS via spring.ldap.embedded.ssl.bundle; client and server configure automatically, and spring.ldap.urls is ignored when the embedded server is active, eliminating test/production config conflicts.
Faster Startup and CI Builds
Executable JAR Startup Acceleration
Fat JARs contain nested JARs. Previously, each class/resource lookup opened a URL connection to each nested JAR. 4.2 searches directly inside nested JARs, optimizes compressed entry reading, and improves resource caching. Startup time and memory allocation during startup decrease; projects with more dependencies benefit more. Auto-configuration sorting and DevTools hot reload also speed up. Zero configuration or code changes required — just upgrade.
Buildpacks Build Cache in Container Registry
Local spring-boot:build-image builds are fast on second run because Docker caches layers locally. CI agents are often ephemeral, losing that cache. 4.2 allows pushing the buildCache image to a registry so all CI nodes share a warm cache.
Maven plugin configuration:
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<configuration>
<image>
<buildCache>
<image>
<name>registry.example.com/cache-${project.artifactId}:latest</name>
</image>
</buildCache>
</image>
</configuration>
</plugin>Gradle equivalent:
bootBuildImage {
buildCache {
image {
name = "registry.example.com/cache-${rootProject.name}:latest"
}
}
}Only buildCache supports registry caching; launchCache and buildWorkspace still require local volumes or bind mounts. Configure docker.publishRegistry credentials if the registry requires authentication.
Default Buildpacks builder base image upgraded from Ubuntu 24.04 to Ubuntu 26.04.
@DefaultValue Placeholders and Other Enhancements
@DefaultValue Supports Property Placeholders
Constructor-bound configuration properties can now reference other properties in default values. Example: payment callback URL defaults to site URL + path.
@ConfigurationProperties("app.pay")
public record PayProperties(
@DefaultValue("${app.site-url}/api/pay/notify") String notifyUrl,
@DefaultValue("30s") Duration timeout) {}app:
site-url: https://shop.example.com
# pay.notify-url not set → becomes https://shop.example.com/api/pay/notifyRequires @ConfigurationPropertiesScan or @EnableConfigurationProperties(PayProperties.class) on the application class.
Additional Minor Improvements
Caffeine async cache : Set spring.cache.caffeine.cache-mode=async.
Per-template/listener KafkaAdmin : Configure independent KafkaAdmin beans via spring.kafka.template.admin and spring.kafka.listener.admin.
Configurable GraphQL HTTP methods : spring.graphql.http.methods (default POST only).
Maven plugin testClasspath parameter : Replaces useTestClasspath; values off, dependencies, all for run and start goals.
Properties migrator fail-fast : spring-boot-properties-migrator can abort startup on errors/warnings, suitable for CI gatekeeping.
SBOM export : jarmode=tools sbom prints/exports Software Bill of Materials from the JAR.
TomcatServerCustomizer : New callback to customize the embedded Tomcat Server object.
Docker Compose enhancements : MySQL/MariaDB random root passwords; RabbitMQ RABBITMQ_DEFAULT_VHOST support.
Deprecation: RestTemplate → RestClient
Spring Framework 7.1 marks RestTemplate as "scheduled for removal". Spring Boot 4.2 deprecates RestTemplate, RestTemplateBuilder, RestTemplateCustomizer, and TestRestTemplate. Migration to RestClient (fluent API) is straightforward.
Before (RestTemplate)
@Service
public class WeatherClient {
private final RestTemplate restTemplate;
public WeatherClient(RestTemplateBuilder builder) {
this.restTemplate = builder.rootUri("https://api.example.com").build();
}
public WeatherInfo today(String city) {
return restTemplate.getForObject("/weather?city={city}", WeatherInfo.class, city);
}
}After (RestClient)
@Service
public class WeatherClient {
private final RestClient restClient;
public WeatherClient(RestClient.Builder builder) {
this.restClient = builder.baseUrl("https://api.example.com").build();
}
public WeatherInfo today(String city) {
return restClient.get()
.uri("/weather?city={city}", city)
.retrieve()
.body(WeatherInfo.class);
}
}Replace RestTemplateCustomizer with RestClientCustomizer for request/response interception.
Test Migration: TestRestTemplate → RestTestClient
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@AutoConfigureRestTestClient
class UserControllerTest {
@Autowired
private RestTestClient restTestClient;
@Test
void shouldReturnUserById() {
restTestClient.get().uri("/api/users/{id}", 1)
.exchange()
.expectStatus().isOk()
.expectBody(UserVO.class)
.value(user -> assertThat(user.username()).isEqualTo("admin"));
}
}RestTestClientprovides built-in assertions, works in both mock (simulated transport) and real-port modes with the same API.
For questions about attribution, corrections or content rights, please contactand we will review it promptly.