Spring Boot 4: Leaner, Safer Apps with Kotlin 2.2 Baseline

Software Development

Spring Boot 4.0 arrives with leaner apps, JSpecify null-safety, and a new Kotlin 2.2 baseline, offering enhanced development experience and robust IntelliJ IDEA support.

Andrey Belyaev

The JetBrains team has been closely following the updates to Spring Boot 4.0 since its first milestones, ensuring that IntelliJ IDEA provides a seamless and reliable development experience. While many core capabilities are inherited directly from Spring Framework 7, Spring Boot continues to act as the crucial adoption enabler, unifying everything with sensible defaults, consistent configuration, standardized starters, and the familiar rapid productivity for application creation.

As the most widely adopted framework in the Java ecosystem, Spring Boot also assists developers in migrating from older JDK versions to newer ones, benefiting from improved performance, more efficient garbage collectors, and modern language features. This significant release of Spring Boot introduces several enhancements, including cleaner modularization for reduced memory footprint, enhanced observability powered by Micrometer, JSpecify as the standard null-safety library, and numerous other minor improvements designed to streamline daily development.

For JetBrains, a key highlight of Spring Boot 4 is the official adoption of Kotlin 2.2 as the baseline version for the framework. This significant achievement is the result of a long-standing collaboration between the JetBrains Kotlin team and the Spring Framework team. Let's delve deeper into Spring Boot 4's new features, particularly through the lens of Kotlin 2.2.

Nullability

The Kotlin compiler and IntelliJ IDEA now offer native support for JSpecify annotations. You will receive a compiler warning if you incorrectly use JSpecify-annotated Java code. Furthermore, IntelliJ IDEA will alert you if you attempt to assign a Java variable annotated with @Nullable to a non-nullable variable in Kotlin, or vice versa.

For example, consider the following Java interface:

@NullMarked
public interface QuoteProvider {
    Quote findQuote(String text);
}

A Kotlin implementation must return a non-nullable Quote object from the overridden findQuote() method:

You’ll encounter the following error message:

IntelliJ IDEA intelligently detects this issue and suggests changing the return type to non-nullable. JSpecify is now the default library for nullability checks across all Spring projects, ensuring that when you create a Spring Boot 4 project in Kotlin, the framework types you utilize are fully null-aware.

API Versioning

API versioning in Kotlin operates very similarly to Java. Thanks to Spring’s well-architected API versioning mechanism, adding a version requires only a few lines of configuration and a single annotation attribute. In Kotlin, the versioned API appears just as concise and straightforward:

@RestController
@RequestMapping("/api", produces = [MediaType.APPLICATION_JSON_VALUE])
class QuoteController(private val klient: QuoteKlient) {
    @GetMapping("quote", version = "1.0")
    fun fetchRandomQuote(): ResponseEntity<Quote> =
        ResponseEntity.ok(klient.fetchRandomQuote())

    @GetMapping("quote", version = "2.0")
    fun fetchRandomQuotes(): ResponseEntity<List<Quote>> =
        ResponseEntity.ok(klient.fetchRandomQuotes())
}

There’s nothing overly complex here, just the typical Kotlin conciseness, with IntelliJ IDEA inspections assisting you in configuring and validating version formats.

Bean Registration

Bean registration is one of the areas where Kotlin truly excels. Its expressiveness and extensibility provide a powerful DSL for dynamically registering beans, especially when the standard @ConditionalOn… annotation family is insufficient.

For instance, instead of the following Java code:

public class QuoteProviderRegistrar implements BeanRegistrar {
    @Override
    public void register(BeanRegistry registry, Environment env) {
        registry.registerBean("quoteProviderDb", QuoteProviderDb.class);
        registry.registerBean("quoteProviderFallback",
                QuoteProviderFallback.class,
                spec -> {
                    spec.fallback();
                    spec.order(1);
                }
        );
    }
}

You can write a significantly more elegant version, eliminating .class calls and lambda boilerplate:

class KuoteProviderRegistrar : BeanRegistrarDsl({
    registerBean<QuoteProviderDb>("quoteProviderDb")
    registerBean<QuoteProviderFallback>(
        name = "quoteProviderFallback",
        fallback = true,
        order = 1
    )
})

Clearly much cleaner, isn't it?

Conclusion

Spring Boot justly remains the most popular framework for Java development. With Spring Boot 4 establishing Kotlin 2.2 as its baseline and offering first-class support, we anticipate even broader adoption of Kotlin among backend developers eager to leverage the latest language features.

You can experience Spring Boot 4 in the 2025.3 Beta release or await the stable version, which is slated for early December. At JetBrains, we are committed to continued close collaboration with the Spring Framework team to ensure Kotlin remains seamlessly integrated and fully supported within the Spring ecosystem.