Backend Development 8 min read

Master Spring Boot 3.4 Upgrade: Key Changes, Configurations & Code Samples

Spring Boot 3.4 introduces performance boosts, enhanced observability, and developer experience improvements, and this guide walks you through the most critical changes—including RestClient auto‑configuration, bean validation updates, graceful shutdown, structured logging formats, dependency upgrades, testing enhancements, and deprecated feature handling—complete with configuration snippets and code examples.

Java Architecture Diary
Java Architecture Diary
Java Architecture Diary
Master Spring Boot 3.4 Upgrade: Key Changes, Configurations & Code Samples

Introduction

Spring Boot 3.4 brings significant performance improvements, enhanced observability, and a better development experience. This guide details the most important changes and provides code examples to help you migrate smoothly.

Main Changes and Enhancements

2.1 RestClient and RestTemplate

2.1.1 New Features

Automatic configuration support: RestClient and RestTemplate now automatically configure multiple HTTP clients, including:

Apache HTTP Components

Jetty Client

Reactor Netty HttpClient

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

# 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

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 Refactor Example

Before:

@ConfigurationProperties(prefix = "pig")
@Validated
public class GatewayConfigProperties {
    private SwaggerProperties swagger;
}

After:

@ConfigurationProperties(prefix = "pig")
@Validated
public class GatewayConfigProperties {
    @Valid // added annotation
    private SwaggerProperties swagger;
}

2.3 Graceful Shutdown

2.3.1 Default Feature

All embedded web servers now enable graceful shutdown by default, including Jetty, Reactor Netty, Tomcat, and Undertow.

2.3.2 Configuration Method

Disable graceful shutdown:

server.shutdown=immediate

2.4 Structured Logging

2.4.1 Supported Formats

Elastic Common Schema (ECS)

{"@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"}

Graylog Extended Log Format (GELF)

{"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"}

Logstash

{"@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}

2.4.2 Configuration Method

Enable ECS format:

# File output using ECS format
logging.structured.format.file=ecs

# Console output using ECS format
logging.structured.format.console=ecs

2.5 Observability Improvements

2.5.1 Application Grouping

# Set application group
spring.application.group=order-processing

# Include group information in logs
logging.include-application.group=true

2.5.2 OTLP Tracing Enhancements

# Enable gRPC transport
management.otlp.tracing.transport=grpc

# Set endpoint
management.otlp.tracing.endpoint=grpc://otel-collector:4317

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

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>3.4.0</version>
    <relativePath/>
</parent>

Test Feature Enhancements

4.1 MockMvc AssertJ Support

@Autowired
private MockMvcTester mockMvcTester;

@Test
void testEndpoint() throws Exception {
    mockMvcTester.get("/api/data")
        .andExpect(status().isOk())
        .andExpect(jsonPath("$.name").value("Sample Data"));
}

Deprecated Feature Handling

5.1 Deprecated Configurations

Before:

management.endpoints.enabled-by-default=false
management.endpoint.health.enabled=true

After:

management.endpoints.access.default=none
management.endpoint.health.access=read-only
JavaBackend DevelopmentObservabilityconfigurationloggingSpring Boot
Java Architecture Diary
Written by

Java Architecture Diary

Committed to sharing original, high‑quality technical articles; no fluff or promotional content.

0 followers
Reader feedback

How this landed with the community

login Sign in to like

Rate this article

Was this worth your time?

Sign in to rate
Discussion

0 Comments

Thoughtful readers leave field notes, pushback, and hard-won operational detail here.