You are here
Home > java >

New Features in Spring Boot 3 and Spring 6

New Features in Spring Boot 3 and Spring 6Spring Boot 3.0 is officially released in November, 2022 with some new features and improvements. This is the first major release of Spring Boot after the release of Spring Boot 2.0 around 4.5 years ago. It is also the first Spring Boot GA release to support Spring Framework 6.0. As a developer, we need to be aware of these updates in order to work smoothly with Spring Boot. Undoubtedly, one of the biggest turn in the new release was the dropping of support for older versions of Java. In this article, we will discuss about ‘New Features in Spring Boot 3 and Spring 6’.

What are the major highlights of the Spring 3.0 Release?

The highlights of the Spring 3.0 Release incorporate:

Who can actually use the Spring Boot 3?

As aforementioned, the biggest turn in the Spring Boot 3.0 is the neglecting support for older versions of Java. Yes, we require minimum Java 17 in order to work with Spring Boot 3.0. Hence, it becomes mandatory to have JDK 17 environment before going to Spring Boot 3.0.

What are the new features in Spring Boot 3 and Spring 6?

One of the important point here to note is that Spring Boot 3.0 builds on and requires Spring Framework 6. Therefore, if your pom.xml points to Spring Boot version 3.0.0, it will automatically download the required dependencies of Spring framework 6. Hence, by default, you will be using Spring Framework 6 while working with Spring Boot 3.0. Please visit a separate article for new features in Spring Framework 6.0. Let’s talk about New Features in Spring Boot 3 here only.

Java 17 Baseline and Java 19 Support

We require Java 17 as a minimum version to work with Spring 3.0. If you are currently using lower versions such as Java 8, Java 11 or Java 14, you need to upgrade your JDK to JDK 17 before starting development of applications using Spring Boot 3.0. At present the latest version of Java is JDK 19. However, Spring Boot 3.0 also works well, and has been tested with JDK 19.

Third-party Library Upgrades

1) Since Java EE has been changed to Jakarta EE, Spring Boot 3.0 has also migrated from Java EE to Jakarta EE APIs for all dependencies. Hence, the package names starting with ‘javax’ need to be changed to ‘jakarta’ accordingly.

For example, some of the commonly used packages will be changed as shown below:

javax.persistence.*   -> jakarta.persistence.*

javax.validation.*    -> jakarta.validation.*

javax.servlet.*       -> jakarta.servlet.*

javax.annotation.*    -> jakarta.annotation.*

javax.transaction.*   -> jakarta.transaction.*

Note: Please note that packages such as javax.sql.* and javax.crypto.* will not change to ‘jakarta.*’ as they are part of Java 17 JDK, not of Java EE. Only those packages which are part of Java EE will change to Jakarta EE.

Wherever possible, Jakarta EE 10 compatible dependencies have been chosen, including:

  • Jakarta Activation 2.1
  • Jakarta JMS 3.1
  • Jakarta JSON 2.1
  • Jakarta JSON Bind 3.0
  • Jakarta Mail 2.1
  • Jakarta Persistence 3.1
  • Jakarta Servlet 6.0
  • Jakarta Servlet JSP JSTL 3.0
  • Jakarta Transaction 2.0
  • Jakarta Validation 3.0
  • Jakarta WebSocket 2.1
  • Jakarta WS RS 3.1
  • Jakarta XML SOAP 3.0
  • Jakarta XML WS 4.0

2) As the Spring Framework is upgraded to version 6, other Spring Projects also upgraded in this release which are:

  • Spring AMQP 3.0.
  • Spring Batch 5.0.
  • Spring Data 2022.0.
  • Spring GraphQL 1.1.
  • Spring HATEOAS 2.0.
  • Spring Integration 6.0.
  • Spring Kafka 3.0.
  • Spring LDAP 3.0.
  • Spring REST Docs 3.0.
  • Spring Retry 2.0.
  • Spring Security 6.0 (see also what’s new).
  • Spring Session 3.0
  • Spring WS 4.0.

3) The latest stable releases of third-party jars are also upgrade wherever possible. Some of the commonly used dependency upgrades include:

  • Couchbase Client 3.4
  • Ehcache 3.10
  • Elasticsearch Client 8.5
  • Flyway 9
  • Groovy 4.0
  • Hibernate 6.1
  • Hibernate Validator 8.0
  • Jackson 2.14
  • Jersey 3.1
  • Jetty 11
  • jOOQ 3.16
  • Kotlin 1.7.20
  • Liquibase 4.13
  • Lettuce 6.2
  • Log4j 2.18
  • Logback 1.4
  • Micrometer 1.10
  • Micrometer Tracing 1.0
  • Neo4j Java Driver 5.2
  • Netty 4.1.77.Final
  • OkHttp 4.10
  • R2DBC 1.0
  • Reactor 2022.0
  • SLF4J 2.0
  • SnakeYAML 1.32
  • Tomcat 10
  • Thymeleaf 3.1.0.M2
  • Undertow 2.2.20.Final

GraalVM Native Image Support

GraalVM Native Images provide a new way to deploy and run Java applications. Compared to the Java Virtual Machine, native images can run with a smaller memory footprint and with much faster startup times.

GraalVM is a high-performance JDK intended to speed up the execution of applications written in Java and other JVM languages while also offering runtimes for JavaScript, Python, and a number of other popular languages. GraalVM offers two ways to run Java applications: on the HotSpot JVM with Graal just-in-time (JIT) compiler or as an ahead-of-time (AOT) compiled native executable.

GraalVM Native Images are standalone executables that can be generated by processing compiled Java applications ahead-of-time. Native Images generally have a smaller memory footprint and start faster than their JVM counterparts. They are well suitable for applications that are deployed using container images. A GraalVM Native Image is a complete, platform-specific executable. We do not need to ship a Java Virtual Machine in order to run a native image.

If you want to know more about it and experiment with GraalVM you can go ahead with the official documentation on “GraalVM Native Image Support”.

Improved Observability with Micrometer and Micrometer Tracing

Observability is the ability to observe the internal state of a running system from the outside. In other words, “how well you can understand the internals of your system by examining its outputs”. It consists of the three pillars logging, metrics and traces. For metrics and traces, Spring Boot uses Micrometer Observation. To create your own observations (which will lead to metrics and traces), you can inject an ObservationRegistry.

1) Spring Boot 3.0 supports the new observation APIs introduced in Micrometer 1.10. The new ObservationRegistry interface can be used to create observations which provides a single API for both metrics and traces. Spring Boot now auto-configures an instance of ObservationRegistry for you. Below code snippet demonstrates the concept of ObervationRegistry.

@Component
public class MyCustomObservation {

   private final ObservationRegistry observationRegistry;

   public MyCustomObservation(ObservationRegistry observationRegistry) {
      this.observationRegistry = observationRegistry;
   }

   public void doSomething() {
      Observation.createNotStarted("doSomething", this.observationRegistry)
                 .lowCardinalityKeyValue("locale", "en-US")
                 .highCardinalityKeyValue("userId", "42")
                 .observe(() -> {
                       // Execute business logic here
                 });
   }
}

2) Spring Boot now auto-configures Micrometer Tracing for you. This includes support for Brave, OpenTelemetry, Zipkin and Wavefront. Spring Cloud Sleuth is replaced by the Micrometer Tracing Framework in the new version.

Example Of Spring Security UserDetailsService Using Spring Boot 3.0

Additionally, we have a separate article as an example of Spring Security UserDetailsService Using Spring Boot 3, which is completely developed using Spring Boot 3.0 by following step by step guidelines provided by Spring Official documentation. Furthermore, you may go through the ‘Spring Boot 3.0 Migration Guide‘ to understand the migration process thoroughly.

This is the list of features for now. Obviously, there are many more. We will update the article time to time accordingly.

For other tutorials on Spring Boot, you may visit Spring Boot Tutorial page.

How is Spring Boot 3 and Spring 6 Releases interconnected?

As aforementioned, Spring Boot 3.0 builds on top of the Spring Framework 6.0. There was a gap of one week between the releases of both. Spring Framework 6.0.0 has released one week before the release of Spring Boot 3.0. In other words, Spring Framework 6.0.0 is the foundation of Spring Boot 3.0. Furthermore, if your pom.xml points to Spring Boot version 3.0.0, it will automatically download the required dependencies of Spring framework 6. Hence, by default, you will be using Spring Framework 6 while working with Spring Boot 3.0.

Although ahead-of-time (AOT) & GraalVM are the new features of Spring Framework 6.0, but they are not useful without a full Spring Boot Stack. They are not good enough in an isolated Spring based application.

The next version Spring Framework 6.1 GA will be released in the next year i.e. November 2023. On the other hand, there will be two releases of Spring Boot, which is Spring Boot 3.0 & 3.1 till November, 2023. It means Spring Framework will have one release per year, whereas Spring boot will have two releases per year with the latest JDK version supports. As per the routine release of JDK, the JDK 21(LTS) will be released by September 2023, which is before the release of Spring Framework 6.1 GA.

Does Spring Boot 3 work with Java 11?

Not at all. Spring Boot 3.0.0 requires JDK 17 as a minimum version to work with it. It is clearly mentioned in the Spring Boot 3.0 release document. If you want to use Java version lower than Java 17, you will have to work with Spring Boot 2.0.

Does Spring Boot 3 support Java 8?

Simply No. In order to work with Spring Boot 3 you must have at least Java 17 installed in your system. Not only installed, your code has to compile with JDK 17. The code compiled with JDK 17 or later version will only be accepted by Spring Boot 3.

close

Leave a Reply

Top