Maru@maru

Dev Hub

Translated from Korean

Spring Boot 3.4 Update: A Look at Structured Logging and Testing Improvements

As deployment environments have increasingly centered around containers and Kubernetes, standardizing logs in JSON format has become a fundamental task in backend development. Previously, to generate this output in Spring Boot applications, developers had to manually create Logback XML files or add third-party library dependencies.

Spring Boot 3.4 has significantly simplified this process. Without complex template files, you can generate structured logs using just a single configuration property, expand support for Java 21 virtual threads, and enjoy refined convenience in the testing framework.

Structured JSON Logging in a Single Line

Spring Boot 3.4 now officially includes built-in auto-configuration for structured logging. With native support for Elastic Common Schema, Logstash, and GELF formats, you can output standard JSON logs to your terminal or files immediately without writing separate XML files.

application.properties configuration example (based on Spring Boot 3.4):

properties

By simply matching the values to your existing infrastructure's log collection pipeline, fields such as date, thread, log level, and MDC are output in a structure optimized for parsing. This reduces the burden of maintaining logging configurations.

Changes in Test Code: @MockitoBean and MockMvcTester

Important improvements have also been made to the testing layer. The previously standard @MockBean and @SpyBean annotations are now deprecated. Instead, the framework recommends using @MockitoBean and @MockitoSpyBean as provided since Spring Framework 6.2.

A new MockMvcTester has also been introduced for verifying the controller layer. While the previous MockMvc chaining syntax was somewhat verbose, you can now use AssertJ-based flexible assertion styles to check response status and body JSON paths.

Test code example (based on Spring Boot 3.4):

java

The integration between the Spring context and Mockito becomes clearer, significantly improving the readability of test code.

Expanded Virtual Thread Support and Easier Bean Injection

The coverage for the spring.threads.virtual.enabled=true option, which enables Java 21 virtual threads, has been broadened. Virtual threads are now automatically applied not only to Tomcat but also to Undertow web server environments and OtlpMeterRegistry metric transmission threads. In I/O-intensive services, you can reliably increase concurrent request processing without additional thread pool tuning.

A @Fallback bean feature has also been added to flexibly manage priorities when multiple beans of the same interface type are registered. This allows for a concise pattern where a bean is not injected if other valid candidates exist, but is injected as the default implementation only when no explicit bean is available.

Practical Guide for Teams

Spring Boot 3.4 is a version that balances development productivity and operational convenience. It is highly recommended for teams that want to strip away complex logging configurations in container environments or those looking to clean up web layer testing with an AssertJ style.

When migrating projects, you can finish the upgrade relatively easily by simply performing a Find & Replace to change @MockBean to @MockitoBean throughout your test code.

Loading comments…