top of page

Spring Boot 3.4: Latest Features and Compatibility Guide

Spring Boot 3.4, released in November 2024, brings a wealth of new features, improvements, and modernizations to the popular Java framework. Built on Spring Framework 6.2 and maintaining the Java 17 and Jakarta EE 9 baselines, this release focuses on enhancing developer productivity, improving observability, and expanding container support.

Table of Contents

Major New Features

1. Enhanced HTTP Client Auto-Configuration

Spring Boot 3.4 introduces comprehensive auto-configuration support for multiple HTTP clients with a new precedence order:

  1. Apache HTTP Components (HttpComponentsClientHttpRequestFactory)

  2. Jetty Client (JettyClientHttpRequestFactory)

  3. Reactor Netty HttpClient (ReactorClientHttpRequestFactory)

  4. JDK HttpClient (JdkClientHttpRequestFactory)

  5. Simple JDK HttpURLConnection (SimpleClientHttpRequestFactory)

Key Configuration Options:

# Select specific client
spring.http.client.factory=reactor

# Control redirect behavior
spring.http.client.redirects=dont-follow

2. New ClientHttpRequestFactoryBuilder Interface

A fluent API for building and customizing HTTP request factories:

@Bean
public HttpComponentsClientHttpRequestFactoryBuilder httpComponentsBuilder() {
    return ClientHttpRequestFactoryBuilder.httpComponents()
        .withDefaultRequestConfigCustomizer(builder -> 
            builder.setProtocolUpgradeEnabled(false));
}

3. Application Grouping

Organize related applications with the new spring.application.group property:

spring.application.group=payment-services
logging.include-application.group=true

This property is automatically included in log messages and OpenTelemetry resources.

Structured Logging

Spring Boot 3.4 introduces built-in structured logging support with three formats:

  • Elastic Common Schema (ECS): logging.structured.format.file=ecs

  • Graylog Extended Log Format (GELF): logging.structured.format.file=gelf

  • Logstash Format: logging.structured.format.file=logstash


# Enable structured console logging
logging.structured.format.console=ecs

# Enable structured file logging
logging.structured.format.file=logstash

Custom structured logging formats can be defined by implementing the StructuredLogFormatter interface.

HTTP Client Enhancements

Auto-Configuration Improvements

The HTTP client auto-configuration now supports RestClient and RestTemplate with:

  • Reactor Netty's HttpClient

  • JDK's HttpClient

  • Consistent redirect handling across all clients

  • Fine-grained customization options

Configuration Properties

# HTTP client selection
spring.http.client.factory=jdk

# Redirect control
spring.http.client.redirects=follow

# Connection timeouts
spring.http.client.connect-timeout=5s

Observability and Monitoring

OpenTelemetry Enhancements

gRPC Transport Support:

management.otlp.tracing.transport=grpc

New OTLP Logging Configuration:

management.otlp.logs.endpoint=http://localhost:4317/v1/logs
management.otlp.logs.headers.authorization=Bearer token

Granular Export Control:

management.otlp.tracing.export.enabled=true
management.wavefront.tracing.export.enabled=false
management.zipkin.tracing.export.enabled=true

Actuator Endpoints Evolution

The endpoint access model has been redesigned with three levels:

  • none - Endpoint disabled

  • read-only - Read operations only

  • unrestricted - Full access

New Configuration:

# Default access level
management.endpoints.access.default=read-only

# Per-endpoint access
management.endpoint.health.access=unrestricted
management.endpoint.metrics.access=read-only

# Maximum permitted access level
management.endpoints.access.max-permitted=read-only

SSL Certificate Monitoring

New SSL certificate health indicators and info endpoint:

management.health.ssl.certificate-validity-warning-threshold=30d

The /actuator/info endpoint now displays:

  • Certificate validity dates

  • Issuer and subject information

  • Expiration warnings

Container and Docker Improvements

Default Builder Change

Spring Boot 3.4 switches to paketobuildpacks/builder-jammy-java-tiny for smaller, more efficient container images. This builder:

  • Supports ARM and x64 platforms

  • Creates smaller images

  • Excludes shell (may affect applications requiring start scripts)

  • Has reduced system libraries

Docker Compose Enhancements

Multiple Configuration Files:

spring.docker.compose.start.arguments=--profile production
spring.docker.compose.stop.arguments=--remove-orphans
spring.docker.compose.arguments=--compatibility

New Container Support:

  • PostgreSQL with POSTGRES_HOST_AUTH_METHOD=trust

  • Redis Stack and Redis Stack Server

  • Grafana LGTM (Logs, Grafana, Traces, Metrics)

  • Hazelcast

  • Enhanced Kafka container support

Testcontainers Improvements

New container support includes:

  • org.testcontainers.kafka.KafkaContainer

  • org.testcontainers.grafana.LgtmStackContainer

  • Redis Stack containers

  • OTLP logging containers

Dynamic Property Registration:

@Bean
public DynamicPropertyRegistrar dynamicProperties(RedisContainer redis) {
    return registry -> registry.add("spring.data.redis.url", redis::getRedisUrl);
}

Testing Enhancements

MockMvcTester Auto-Configuration

When AssertJ is available, Spring Boot auto-configures MockMvcTester:

@SpringBootTest
class WebLayerTest {
    
    @Autowired
    private MockMvcTester mockMvcTester;
    
    @Test
    void shouldReturnDefaultMessage() {
        mockMvcTester.get("/")
            .assertThat()
            .hasStatus(HttpStatus.OK)
            .hasContentType(MediaType.APPLICATION_JSON)
            .bodyJson().isEqualTo("{\"message\": \"Hello World\"}");
    }
}

Annotation Migration

@MockBean and @SpyBean are deprecated in favor of Spring Framework's:

  • @MockitoBean

  • @MockitoSpyBean

Note: The new annotations don't support @Configuration classes.

Data Access Updates

Multiple DataSource Support

Improved support for multiple DataSources without complex configuration:

@Configuration
public class DataSourceConfiguration {
    
    @Bean
    @Primary
    public DataSource primaryDataSource() {
        return DataSourceBuilder.create()
            .url("jdbc:h2:mem:primary")
            .build();
    }
    
    @Bean(defaultCandidate = false)
    public DataSource secondaryDataSource() {
        return DataSourceBuilder.create()
            .url("jdbc:h2:mem:secondary")
            .build();
    }
}

Enhanced Connection Details

Improved connection details support for:

  • Cassandra

  • Neo4j

  • Couchbase (with client certificate authentication)

  • Enhanced Pulsar configuration

Pulsar Enhancements

New Configuration Properties:

# Default tenant and namespace
spring.pulsar.defaults.topic.tenant=public
spring.pulsar.defaults.topic.namespace=default

# Concurrency settings
spring.pulsar.client.threads.io=4
spring.pulsar.client.threads.listener=2
spring.pulsar.listener.concurrency=2

# Subscription configuration
spring.pulsar.consumer.subscription.name=my-subscription

Breaking Changes

Important Behavioral Changes

  1. Graceful Shutdown Default: Web server graceful shutdown is now enabled by default

# To restore immediate shutdown server.shutdown=immediate
  1. Bean Validation Changes: Nested property validation now requires explicit @Valid annotation

  2. Conditional Bean Behavior: @ConditionalOnBean and @ConditionalOnMissingBean behavior changed when annotation attribute is set

  3. YAML Configuration: Empty maps are now ignored in YAML processing

Dependency Updates

Major dependency upgrades include:

  • Hibernate 6.6

  • Jackson 2.18.0

  • Kafka 3.8

  • Elasticsearch Client 8.15

  • JUnit Jupiter 5.11

  • Log4j 2.24

Removed Components

Spring Boot no longer manages:

  • OkHttp version (manual dependency management required)

  • Classes deprecated in 3.2 and marked for 3.4 removal

Compatibility Matrix

ComponentVersionJava CompatibilitySpring Framework6.2Java 17+Spring Boot3.4.xJava 17+Jakarta EE9.xHibernate6.6Java 17+Jackson2.18.0Java 8+Kafka3.8Java 11+Elasticsearch8.15Java 17+JUnit5.11Java 8+

Supported Platforms

  • JVM: Oracle JDK, OpenJDK, GraalVM

  • Native: GraalVM Native Image

  • Containers: Docker, Podman

  • Cloud: AWS, Azure, GCP, Cloud Foundry

  • Application Servers: Tomcat 10.1, Jetty 12, Undertow 2.3

Migration Guide

Pre-Migration Checklist

  1. Verify Java Version: Ensure Java 17+ is installed

  2. Dependency Review: Check for deprecated dependencies

  3. Custom Configurations: Review custom auto-configurations

  4. Test Coverage: Ensure comprehensive test coverage

Step-by-Step Migration

1. Update Build Configuration

Maven:

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

Gradle:

plugins {
    id("org.springframework.boot") version "3.4.0"
    id("io.spring.dependency-management") version "1.1.4"
}

2. Address Breaking Changes

Update Validation Annotations:

@ConfigurationProperties("app")
@Validated
public class AppProperties {
    @Valid  // Add @Valid for nested validation
    private Database database = new Database();
    
    // getters and setters
}

Update Test Annotations:

// Replace @MockBean with @MockitoBean
@MockitoBean
private UserService userService;

// Replace @SpyBean with @MockitoSpyBean
@MockitoSpyBean
private EmailService emailService;

3. Update Configuration Properties

Actuator Endpoints:

# Old (deprecated)
management.endpoints.enabled-by-default=true
management.endpoint.health.enabled=true

# New
management.endpoints.access.default=read-only
management.endpoint.health.access=unrestricted

4. Leverage New Features

Enable Structured Logging:

logging.structured.format.console=ecs
logging.structured.format.file=logstash

Configure HTTP Client:

spring.http.client.factory=reactor
spring.http.client.redirects=follow

Common Migration Issues

1. HtmlUnit Upgrade

Update imports and dependencies:

// Old import
import com.gargoylesoftware.htmlunit.WebClient;

// New import
import org.htmlunit.WebClient;

2. WebJars Locator

Update dependency:

<!-- Replace -->
<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>webjars-locator-core</artifactId>
</dependency>

<!-- With -->
<dependency>
    <groupId>org.webjars</groupId>
    <artifactId>webjars-locator-lite</artifactId>
</dependency>

3. Native Image Metadata

For Spring Boot 3.4.0, update GraalVM metadata:

Maven:

<plugin>
    <groupId>org.graalvm.buildtools</groupId>
    <artifactId>native-maven-plugin</artifactId>
    <configuration>
        <metadataRepository>
            <version>0.3.14</version>
        </metadataRepository>
    </configuration>
</plugin>

4. Tomcat APR Configuration

For Java 24+:

server.tomcat.use-apr=when-available

Performance Improvements

Spring Boot 3.4 includes several performance optimizations:

Virtual Thread Support

Enhanced virtual thread support for:

  • OtlpMeterRegistry

  • Undertow web server

  • Micrometer observations

  • Spring Data reactive repositories

Container Image Optimizations

  • Smaller base images with jammy-java-tiny builder

  • Multi-platform support (ARM64/AMD64) out of the box

  • Improved layer caching for faster builds

Startup Performance

  • Reduced memory footprint during startup

  • Faster bean initialization with improved condition matching

  • Optimized WebJars resolution with webjars-locator-lite

Security Enhancements

SSL/TLS Improvements

  • SSL Bundle integration with JavaMailSender

  • Certificate monitoring and health checks

  • Automated certificate expiration warnings

Authentication Updates

  • Client certificate support for Couchbase

  • Enhanced SAML2 configuration with Base64ProtocolResolver

  • Improved Spring Security logout auditing

Conclusion

Spring Boot 3.4 represents a significant step forward in the framework's evolution, focusing on developer experience, observability, and modern deployment patterns. The introduction of structured logging, enhanced HTTP client support, and improved container tooling makes it an compelling upgrade for teams looking to modernize their Spring applications.

Key takeaways for migration:

  • Plan for the breaking changes, especially around validation and test annotations

  • Leverage new features like structured logging and enhanced HTTP client configuration

  • Take advantage of improved container and Docker Compose support

  • Consider the performance benefits of the new virtual thread enhancements

Whether you're building new applications or migrating existing ones, Spring Boot 3.4 provides a solid foundation for modern Java development with excellent compatibility and extensive feature set.

Resources

This blog post covers the major features and changes in Spring Boot 3.4. For complete details and minor updates, refer to the official release notes and documentation.

Comments


bottom of page