BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage News Josh Long at Devoxx UK: Showcasing Bootiful Spring 6 and Spring Boot 3

Josh Long at Devoxx UK: Showcasing Bootiful Spring 6 and Spring Boot 3

Bookmarks

At his Devoxx UK presentation, Josh Long, Spring developer advocate at VMware, coded his way through the new features coming in Spring Framework 6, and Spring Boot 3. He emphasized the language-level benefits of the latest Java versions starting with version 17.

Long started the presentation by mentioning that he considers Spring Boot 3 (released on the US Thanksgiving Day in 2023) the biggest release since version 1 (released on April Fool’s Day in 2014). During his presentation, he showcased the multiple features added to this version by coding a "production-grade" REST service and the corresponding client.

He uses the spring initialize, pointing out that even if you can choose between the gradle (both groovy or kotlin) and maven build tools, the default is now gradle with groovy. When choosing the Java version, he emphasized that the current default, Java version 17, is the minimal logical choice over 11 and 8, as version 17 is the baseline for Spring Boot 3.

...You should choose 11 or 8 only when you want to show people what not to do

Long added a series of dependencies via the initializr for JDBC, Web, GraalVM and Spring Boot Actuator. The generated zip file was downloaded and opened in IntelliJ IDEA. He coded a service using the old-fashioned JdbcTemplate, RowMapper and Service, which returned the new entities defined as Java records. In the next step, he added a database schema and data by creating the corresponding SQL files in the resources folder.

The HttpCcontroller implementation followed, which is transformed into production-worthy code by the addition of validation and centralization of the error handling by writing an aspect. To create a standard representation of the errors, he used the newly added support for RFC-7807: Problem Details for HTTP APIs that returns a ProblemDetais object when any exception is handled. The behaviour can be enabled by setting spring.mvc.problemdetails.enabled=true in application.properties. Adding the HttpRequest into the exception handling method, he underlined that the HttpServletRequest now has a new home in jakarta.servlet.http package. Which, even though it seems just a small change, it required sustained effort and collaboration from the Java community. Spring 6 is the new baseline, and everything "just works" with these new types.

…finally we have Jakarta EE 10 and this means that as a community we can move faster as a community

Next, he addressed observability: "I cannot tell if I am winning if I don’t know when I am losing". There are two ways to approach this:

  • Metrics - statistics. How many requests do you have, how many customers are logged in, etc
  • Tracing - the details of an individual request to the system

To avoid circular dependencies and to enable tracing at any level, in Spring 6, the sleuth project used for tracing in the "old world" was removed, and now micrometer can do both tracing and metrics. In order to take advantage of all these, actuators should be enabled in the project.

Long stated that "now that the application is production ready", it can be assembled into a runnable container using buildpacks.io. The other necessary thing to be done is to make the application as efficient and small as possible. He reminded the audience that Java is an efficient technology and that garbage collection and the JIT do a good job of keeping Java efficient.

As GraalVM is an alternative that could make things even better, Spring 3 and Spring 6 provide a mechanism to generate native images. In his humoristic seriosity, Long mentioned that as he felt the compilation was taking too long, he decided to ask for either elevator music or at least a notification, like the toasters, to alert him when the compilation was done.

As the service was completed, he shifted focus to implementing a client that consumed the implemented service. During the implementation, he showcased the new @GetExchange, which is the client-side equivalent of @GetMapping from the server side. Initially, this was found it in parts of Spring Cloud, but now it is part of the Spring framework, and it supports any implementation (HTTP, Reactive or RSocket). By providing the benefit of aggregating multiple calls to the same service, he introduced the newly added support for GraphQL.

Concluding his presentation, he reiterated the fact that Spring 6 and Spring Boot 3 are a new baseline; both from the perspective of the Jakarta EE namespace and also with the newly added support for native compilation.

About the Author

Rate this Article

Adoption
Style

BT