Spring Framework 6 and Spring Boot 3 Released

Advertisements

A new generation of Spring Framework has been released, after 5 years with Spring Framework 5.x, in November 2022, Spring Framework 6 has been released. And with it, Spring Boot has a new major version available, Spring Boot 3.

Now the question is: What’s new on these new versions? There are several new features, some other deprecated features have been removed. But there are 4 main features on these released versions.

  • Java 17 is the baseline
  • Support to Jakarta EE 9 and 10 specifications and packages.
  • Observability improved with Micrometer
  • Native compilation using GraalVM

Java 17 baseline

Even though previous version of Spring Framework and Spring Boot had support to run on Java 17, the base line is not the latest LTS version. For these releases the internally compile the libraries and uses many of the new features provided in Java 17. It means that you will need to migrate also your base line code to Java 17 to start using Spring Framework 6 or Spring Boot 3.

Jakarta EE Support

Spring Framework uses some the Java EE specifications, for example, for Servlets, JPA, or support CDI annotations. When Java EE moves to the eclipse foundation and change the name to Jakarta EE, those specification also had to change the packages from javax.* to jakarta.* .

Therefore import like javax.servlet.http.HttpServletRequest now are jakarta.servlet.http.HttpServletRequest. Or javax.persistence.Entity is replaced by. jakarta.persistence.Entity.

Observability

With Spring 6, there was an Observability initiative that ended up with a new Micrometer Observation API and with the former Spring Cloud Sleuth project migrated to Micrometer Tracing. This is more for efficiently recording application metrics with Micrometer, and implementing tracing through providers, such as OpenZipkin or OpenTelemetry.

There’s auto-configuration for all of these in Spring Boot 3, and the Spring projects are working on instrumenting themselves using the Observation API.

Native Compilation

This feature is a response to new frameworks like Quarkus and Micronaut, which have been gaining popularity because of the lower resource usage. Now, we can generate native code without third party plugins or add-ons. Just by running mvn springboot:aot-generate.

Other new Features

The new version is not limited to those new features mentioned above. There are a lot of enhancements, for example:

Advertisements
  • Support for Elastic-search’s new Java client
  • Support for Flyway 9
  • Support for Hibernate 6.1

How to get started on it?

For sure, you might be wondering at this moment, what I need to start using it.

New Project from scratch

If you want to create a new project from scratch, it is as simple as using the Spring Initializer. Select Spring Boot 3.0 in the options, generate and download a project with all the required initial configuration.

Or you can created manually a project using gradle or maven and add the dependency: Group id org.springframework.boot , artifactId spring-boot-starter-parent and version 3.0.0 .

<parent>
	<groupId>org.springframework.boot</groupId>
	<artifactId>spring-boot-starter-parent</artifactId>
	<version>3.0.0</version>
</parent>

If you want to create executable jar, you can add the plugin.

<build>
    <plugins>
        <plugin>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-maven-plugin</artifactId>
        </plugin>
    </plugins>
</build>


Migrating from a previous version

You might already have a project build on Spring 5 and Spring Boot 2.7.x, or previous versions. The first step should be migrate your existing code to use the latest versions of Spring 5 and Spring Boot.

Then, we can use the “experimental tool” Spring Migrator, that will help us to move our code from Spring Boot 2.7.x to Spring Boot 3.0.0.

If you are not sure about using that tool, let’s do it manually.

  • First migrate your code to be compiled and run on Java 17.
  • Remove deprecated usages reported on Spring 2.7.x. Because Spring 3.0.0 is removing those deprecated features.
  • Replace javax to jakarta packages in the imports.
  • Upgrade to Apache HttpClient 5. Required if you are using Rest Template.
  • Spring Data prefix, all the configuration for spring data MUST start now with the spring.data prefix, for example: spring.elasticsearch should be replaced to spring.data.elasticsearch

References

Advertisements

Leave a Reply

Your email address will not be published. Required fields are marked *