What's New in Spring Boot 3.4.0

What's New in Spring Boot 3.4.0

Spring Boot 3.4.0 is here, and it brings a host of enhancements to make modern application development faster, more efficient, and more robust. Here’s a complete overview of the latest features with examples to get you started.


1. Application Version Management

Spring Boot introduces the spring.application.version property to easily set and access your application’s version.

Example: In application.properties:

spring.application.version=1.2.0        

Access in code:

@Value("${spring.application.version}")
private String appVersion;

@PostConstruct
public void printVersion() {
    System.out.println("App Version: " + appVersion);
}        


2. Virtual Thread Improvements

Spring now supports virtual threads natively for task scheduling and asynchronous processing, removing the need for @EnableScheduling.

Example:

@Component
public class VirtualThreadExample {

    @Scheduled(fixedRate = 2000)
    public void task() {
        System.out.println("Running on thread: " + Thread.currentThread());
    }
}        


3. Enhanced Docker Compose Support

Spring Boot now supports multiple Docker Compose files, allowing you to define configurations for different environments.

Example:

spring.docker.compose.files=docker-compose.override.yml,docker-compose.prod.yml        

Spring merges these configurations when starting the application.


4. Prometheus Client 1.x Support

Spring Boot now supports the Prometheus 1.x client for better observability.

Example: Add the Prometheus dependency:

<dependency>
    <groupId>io.prometheus</groupId>
    <artifactId>simpleclient</artifactId>
    <version>1.0.0</version>
</dependency>        


5. Structured Logging Improvements

The Spring Boot startup banner is automatically disabled when using JSON or structured logging to reduce clutter.

Example: With logback-spring.xml:

<configuration>
    <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender">
        <encoder>
            <pattern>{"timestamp":"%d","level":"%p","message":"%m"}</pattern>
        </encoder>
    </appender>
</configuration>        


6. SBOM Actuator Endpoint

Spring Boot now provides an SBOM (Software Bill of Materials) endpoint to support software supply chain security.

Example: Enable the SBOM endpoint in application.properties:

management.endpoint.sbom.enabled=true        

Access it via /actuator/sbom.


7. ApplicationContextRunner Enhancements

Testing ApplicationContext is more powerful with added support for running with custom configurations.

Example:

new ApplicationContextRunner()
    .withPropertyValues("spring.application.name=TestApp")
    .run(context -> assertThat(context).hasSingleBean(SomeBean.class));        


8. Hibernate Auto-Configuration Enhancements

Hibernate’s native properties are now supported directly, improving compatibility and configuration flexibility.

Example:

spring:
  jpa:
    properties:
      hibernate.dialect: org.hibernate.dialect.PostgreSQLDialect
      hibernate.show_sql: true        


9. New Actuator Features

  • System Endpoint Enhancements: Expose additional JVM-specific details such as available processors and uptime.
  • Optimized Metrics Collection: Metrics collection for HTTP exchanges and request bodies is now more efficient.

Example: Enable JVM metrics:

management.endpoint.system.enabled=true
management.metrics.enable.http=true        


10. Conditional Annotations

@ConditionalOnAvailableEndpoint now supports simplified syntax with a value alias.

Example:

@Configuration
@ConditionalOnAvailableEndpoint(MyCustomEndpoint.class)
public class MyConfig {
    @Bean
    public MyService service() {
        return new MyService();
    }
}        


11. Expanded Build Image Support

New options for customizing Spring Boot’s container image building process are included.

Example:

./mvnw spring-boot:build-image -Dspring-boot.build-image.environment.BUILDPACK_ENV=prod        


Why Upgrade?

Spring Boot 3.4.0 is packed with new features aimed at streamlining development, optimizing performance, and enhancing observability. These updates cater to both modern enterprise applications and cloud-native solutions.

For a detailed breakdown, check the official release notes and the Spring blog

Let’s build smarter, faster, and more secure applications with Spring Boot! ??

要查看或添加评论,请登录

Hushen Savani的更多文章

社区洞察

其他会员也浏览了