Master Spring Boot 3.4: Key Changes, New Features, and Migration Guide
This comprehensive guide explores Spring Boot 3.4’s performance boosts, enhanced observability, and developer experience improvements, detailing major changes such as RestClient/RestTemplate auto‑configuration, bean validation updates, graceful shutdown, structured logging formats, observability enhancements, dependency upgrades, testing enhancements, and deprecated feature handling, with practical code snippets.
1. Introduction
Spring Boot 3.4 brings significant performance improvements, enhanced observability, and a better development experience. This guide highlights the most important changes and provides code examples to help you migrate smoothly.
2. Major Changes and Enhancements
2.1 RestClient and RestTemplate
2.1.1 New Features
Automatic configuration support for multiple HTTP clients, including Apache HTTP Components, Jetty Client, Reactor Netty HttpClient, and JDK HttpClient.
2.1.2 Client Priority Order
Apache HTTP Components (HttpComponentsClientHttpRequestFactory)
Jetty Client (JettyClientHttpRequestFactory)
Reactor Netty HttpClient (ReactorClientHttpRequestFactory)
JDK HttpClient (JdkClientHttpRequestFactory)
Simple JDK HttpURLConnection (SimpleClientHttpRequestFactory)
2.1.3 Configuration Example
<code># 1. Use http-components
spring.http.client.factory=http-components
# 2. Use jetty
spring.http.client.factory=jetty
# 3. Disable redirects
spring.http.client.redirects=dont-follow</code>2.1.4 Custom Client Example
2.2 Bean Validation for Configuration Properties
2.2.1 Main Changes
Validation now strictly follows the Bean Validation specification.
Nested properties are validated only when the field is annotated with
@Valid.
2.2.2 Refactoring Example
Before:
<code>@ConfigurationProperties(prefix = "pig")
@Validated
public class GatewayConfigProperties {
private SwaggerProperties swagger;
}</code>After:
<code>@ConfigurationProperties(prefix = "pig")
@Validated
public class GatewayConfigProperties {
@Valid // add this annotation
private SwaggerProperties swagger;
}</code>2.3 Graceful Shutdown
2.3.1 Default Feature
All embedded web servers (Jetty, Reactor Netty, Tomcat, Undertow) now enable graceful shutdown by default.
2.3.2 Configuration
Disable graceful shutdown:
<code>server.shutdown=immediate</code>2.4 Structured Logging
2.4.1 Supported Formats
Elastic Common Schema (ECS)
<code>{"@timestamp":"2024-01-01T10:15:00.067462556Z","log.level":"INFO","process.pid":39599,"process.thread.name":"main","service.name":"simple","log.logger":"org.example.Application","message":"No active profile set, falling back to 1 default profile: \"default\"","ecs.version":"8.11"}</code>Graylog Extended Log Format (GELF)
<code>{"version":"1.1","short_message":"No active profile set, falling back to 1 default profile: \"default\"","timestamp":1725958035.857,"level":6,"_level_name":"INFO","_process_pid":47649,"_process_thread_name":"main","_log_logger":"org.example.Application"}</code>Logstash
<code>{"@timestamp":"2024-01-01T10:15:00.111037681+02:00","@version":"1","message":"No active profile set, falling back to 1 default profile: \"default\"","logger_name":"org.example.Application","thread_name":"main","level":"INFO","level_value":20000}</code>2.4.2 Configuration
Enable ECS format:
<code># File output using ECS format
logging.structured.format.file=ecs
# Console output using ECS format
logging.structured.format.console=ecs</code>2.5 Observability Improvements
2.5.1 Application Grouping
<code># Set application group
spring.application.group=order-processing
# Include group information in logs
logging.include-application.group=true</code>2.5.2 OTLP Tracing Enhancements
<code># Enable gRPC transport
management.otlp.tracing.transport=grpc
# Set endpoint
management.otlp.tracing.endpoint=grpc://otel-collector:4317</code>3. Dependency Version Upgrades
3.1 Spring Core Framework
Spring Framework → 6.2
Spring Data → 2024.1
Spring Security → 6.4
Spring Batch → 5.2
3.2 Third‑Party Libraries
Hibernate → 6.6
Jackson → 2.18.0
Micrometer → 1.14
Reactor → 2024.0
Testcontainers → 1.20.3
3.3 Maven Configuration Example
<code><parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>3.4.0</version>
<relativePath/>
</parent></code>4. Testing Enhancements
4.1 MockMvc AssertJ Support
<code>@Autowired
private MockMvcTester mockMvcTester;
@Test
void testEndpoint() throws Exception {
mockMvcTester.get("/api/data")
.andExpect(status().isOk())
.andExpect(jsonPath("$.name").value("Sample Data"));
}</code>5. Deprecated Feature Handling
5.1 Deprecated Configurations
Before:
<code>management.endpoints.enabled-by-default=false
management.endpoint.health.enabled=true</code>After:
<code>management.endpoints.access.default=none
management.endpoint.health.access=read-only</code>macrozheng
Dedicated to Java tech sharing and dissecting top open-source projects. Topics include Spring Boot, Spring Cloud, Docker, Kubernetes and more. Author’s GitHub project “mall” has 50K+ stars.
How this landed with the community
Was this worth your time?
0 Comments
Thoughtful readers leave field notes, pushback, and hard-won operational detail here.