Spring Boot 3.x

Saurav Kumar
9 min readJun 20, 2023

--

Java 17 baseline and Java 19 support:

  • The term “baseline version” refers to the minimum version of Java that a software application can run on. In the case of Spring Boot 3.0, the baseline version is Java 17. This means that Spring Boot 3.0 will only run on Java 17 or higher.
  • Java 17 is the latest long-term support (LTS) version of Java. LTS versions of Java are supported by Oracle for a period of 10 years, which makes them a good choice for production applications.
  • Spring Boot 3.0 requires Java 17 or higher. It will not work with older versions of Java.

Spring Framework 6 and Jakarta EE 9:

  • Spring Framework 6 is the latest version of the Spring Framework, a popular Java framework for developing enterprise applications. It is based on Java 17 and Jakarta EE 10, which is the successor to Java EE.
  • Here are some of the benefits of using Spring Boot 3.0 with Jakarta EE 9:

You can use the latest features of Java 17 and Jakarta EE 9.

You can use the Spring Boot ecosystem, which includes a number of popular libraries and tools for developing enterprise applications.

You can create native executables for your applications, which can improve performance.

  • If you are developing enterprise applications, I recommend using Spring Boot 3.0 with Jakarta EE 9. It is a powerful combination that can help you to develop high-quality, scalable, and performant applications.
  • If you are currently using Spring Boot 2.x, you can upgrade to Spring Boot 3.0 to take advantage of these benefits. However, you will need to make some changes to your code, as Jakarta EE 9 has changed the Java namespace from javax.* to jakarta.*.

GraalVM Native Image Support:

  • GraalVM Native Image is a technology that allows you to compile Java applications ahead of time (AOT) into a native executable. This means that the application does not need to be interpreted by the Java Virtual Machine (JVM) at runtime, which can significantly improve performance.
  • Spring Boot 3.0 includes built-in support for GraalVM Native Image, which makes it easy to create native executables from your Spring Boot applications. To do this, you simply need to add the spring-boot-maven-plugin or spring-boot-gradle-plugin to your project and configure it to build a native image.
  • Once you have built a native image, you can run it directly on your machine without the need for a JVM. This can significantly improve the startup time and memory footprint of your application.
  • Here are some of the benefits of using GraalVM Native Image with Spring Boot:

Faster startup time: Native images start up much faster than JVM-based applications because they do not need to be interpreted by the JVM.

Reduced memory footprint: Native images have a smaller memory footprint than JVM-based applications because they do not need to load the entire JVM.

Improved performance: Native images can perform better than JVM-based applications because they are compiled into native code.

  • However, there are also some limitations to using GraalVM Native Image with Spring Boot:
  • Not all features are supported: Not all Java features are supported by GraalVM Native Image. This means that you may need to make some changes to your application code in order to build a native image.
  • More complex to build: Building a native image is more complex than building a JVM-based application. This is because you need to have a GraalVM installation and you need to configure the build process to build a native image.
  • Overall, GraalVM Native Image can be a great way to improve the performance of your Spring Boot applications. However, it is important to be aware of the limitations before you decide to use it.

Log4j2 Enhancements:

  • Spring Boot 3.0 includes a number of enhancements to Log4j2, including:
  • Profile-specific configuration: This allows you to configure different Log4j2 settings for different Spring profiles. For example, you could have a separate set of logging settings for your development environment and your production environment.
  • Environment property lookup: This allows you to look up properties from the Spring Environment in your Log4j2 configuration. This can be useful for things like dynamically setting the log level based on the value of a property.
  • Log4j2 system properties: This allows you to set Log4j2 properties using system properties. This can be useful for things like setting the log level for a specific logger.
  • In addition to these enhancements, Spring Boot 3.0 also supports the new Log4j 2.17.0 release. This release includes a number of security fixes, as well as some new features.
  • Overall, the Log4j2 enhancements in Spring Boot 3.0 make it easier to configure and use Log4j2 in your applications. They also provide support for the latest version of Log4j 2.
  • Here are some examples of how you can use these enhancements:

You could configure different log levels for your development and production environments by using the profile-specific-configuration enhancement.

You could dynamically set the log level for a specific logger based on the value of a property by using the environment-property-lookup enhancement.

You could set the log level for all loggers using a system property by using the log4j2-system-properties enhancement.

Improved @ConstructorBinding Detection:

  • In Spring Boot 2.x, you had to annotate your class with the @ConstructorBinding annotation if you wanted to use constructor binding to inject dependencies into your beans. This could be a bit tedious, especially if you had a lot of classes that needed to be constructor-bound.
  • In Spring Boot 3.0, this has been improved. Now, if your class has a single parameterized constructor, Spring Boot will automatically detect that you want to use constructor binding, and no annotation is necessary. This makes it much easier to inject dependencies into your beans, and it also makes your code more concise.
  • For example, the following code would have required the @ConstructorBinding annotation in Spring Boot 2.x:
@ConfigurationProperties(prefix = "my.properties")
@ConstructorBinding
public class MyProperties {
private String name;
public MyProperties(String name) {
this.name = name;
}
}

However, in Spring Boot 3.0, the annotation is no longer necessary:

@ConfigurationProperties(prefix = "my.properties")
public class MyProperties {
private String name;
public MyProperties(String name) {
this.name = name;
}
}
  • There are a few things to keep in mind when using constructor binding in Spring Boot 3.0:

You can still use the @ConstructorBinding annotation if you want to, but it is no longer required.

If your class has more than one parameterized constructor, you will still need to use the @ConstructorBinding annotation to tell Spring Boot which one to use.

Constructor binding can only be used with beans that are created using @EnableConfigurationProperties or configuration property scanning.

Observability:

  • Spring Boot 3.0 includes enhanced observability features, including support for Micrometer and Micrometer Tracing. This makes it easier to monitor and troubleshoot your applications.
  • Observability is the ability to measure the internal state of a system only by its external outputs. In the context of Spring Boot applications, this means being able to collect metrics, logs and traces about your application’s performance and behavior.
  • Spring Boot 3.0 includes enhanced observability features that make it easier to collect and analyze this data. These features include:

Support for Micrometer: Micrometer is a library that provides a standard way to collect metrics from Java applications. Spring Boot 3.0 automatically configures Micrometer to collect metrics for your application.

Support for Micrometer Tracing: Micrometer Tracing provides a way to track the flow of requests through your application. This can be helpful for debugging problems and identifying performance bottlenecks.

  • These new observability features make it easier to monitor and troubleshoot your Spring Boot applications. By collecting metrics, logs, and traces, you can get a better understanding of how your application is performing and identify any problems that may be occurring.
  • Here are some specific examples of how you can use the observability features in Spring Boot 3.0:

You can use metrics to track the performance of your application, such as the number of requests per second, the average response time, and the memory usage.

You can use logs to troubleshoot problems in your application. For example, you can use logs to see what exceptions are being thrown or to track the flow of requests through your application.

You can use traces to identify performance bottlenecks in your application. For example, you can use traces to see which requests are taking the longest to execute or to identify which parts of your application are causing the most load.

Auto-configuration:

  • Spring Boot 3.0 includes enhanced auto-configuration features, which can make it easier to configure your applications.
  • Spring Boot auto-configuration is a feature that automatically configures your Spring application based on the jar dependencies that you have added. This can make it much easier to configure your applications, as you don’t have to manually configure all of the beans that your application needs.
  • In Spring Boot 3.0, the auto-configuration features have been enhanced in a number of ways. For example, there are now more auto-configuration classes that can be used to configure different aspects of your application. Additionally, the auto-configuration classes have been made more intelligent, so that they can better understand the dependencies that your application has.
  • As a result of these enhancements, Spring Boot 3.0 makes it even easier to configure your applications. You can now focus on writing your business logic, and Spring Boot will take care of the rest.
  • Here are some specific examples of the enhanced auto-configuration features in Spring Boot 3.0:

More auto-configuration classes: There are now more than 200 auto-configuration classes in Spring Boot 3.0. This means that there is a greater chance that Spring Boot will be able to automatically configure the features that your application needs.

More intelligent auto-configuration: The auto-configuration classes in Spring Boot 3.0 are more intelligent than in previous versions. This means that they can better understand the dependencies that your application has, and they can automatically configure the features that your application needs.

Better support for Spring Boot starter dependencies: Spring Boot starter dependencies are a great way to simplify the configuration of your Spring applications. In Spring Boot 3.0, the support for Spring Boot starter dependencies has been improved. This means that you can now use Spring Boot starter dependencies to automatically configure even more features of your application.

  • Overall, the enhanced auto-configuration features in Spring Boot 3.0 make it even easier to configure your applications. If you are using Spring Boot, I highly recommend upgrading to Spring Boot 3.0 so that you can take advantage of these new features.

Security:

  • Spring Boot 3.0 includes enhanced security features, including support for the latest version of Spring Security.
  • Spring Boot 3.0 includes a number of new security features, including:

Support for the latest version of Spring Security: Spring Security is a powerful framework for securing Spring applications. Spring Boot 3.0 includes support for the latest version of Spring Security, which includes a number of new features and improvements.

Enhanced password storage: Spring Boot 3.0 includes enhanced password storage, which makes it more difficult for attackers to crack passwords.

Improved CSRF protection: CSRF (Cross-site request forgery) is a type of attack that can be used to trick users into performing actions they didn’t intend to perform. Spring Boot 3.0 includes improved CSRF protection, which makes it more difficult for attackers to exploit this vulnerability.

New security annotations: Spring Boot 3.0 includes a number of new security annotations that make it easier to secure Spring applications.

  • These new security features make Spring Boot 3.0 a more secure framework for developing web applications.
  • In addition to these new features, Spring Boot 3.0 also includes a number of other security improvements, such as:

Improved documentation: The documentation for Spring Boot security has been improved, making it easier for developers to understand how to secure their applications.

New security tutorial: A new security tutorial has been added to the Spring Boot documentation, which provides step-by-step instructions on how to secure a Spring Boot application.

Security starter: A new security starter has been added to the Spring Boot project, which makes it easy to add security to a Spring Boot application.

  • Overall, Spring Boot 3.0 includes a number of new security features and improvements that make it a more secure framework for developing web applications.

Source code reference

The source code for the examples in this blog can be found on GitHub:

https://github.com/sauravkumarshah/spring-boot-3.x-features

--

--

Saurav Kumar

Experienced Software Engineer adept in Java, Spring Boot, Microservices, Kafka & Azure.