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

MMS Founder
MMS Olimpiu Pop

Article originally posted on InfoQ. Visit InfoQ

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 emphasizing the benefits at the Java language level in the latest versions starting with version 17.

He starts the presentation by mentioning that he considers Spring Boot 3(released on the Thanksgiven Day in 2023) the biggest release since version 1 (released on April Fool’s Day in 2014). During his presentation, he intends to showcase the multiple features added to this version by coding a “production-grade” REST service and the corresponding client.

He uses the spring initializr pointing out that even if you can choose between gradle(both groovy or kotlin) and maven the default is now gradle with groovy. When choosing the Java version he emphasizes that the current default, Java version 17, is the minimal logical choice because 11 and 8 are non-choices 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

Further, he generated a project supporting JDBC, Web, GraalVM and Spring Boot Actuator. The resulting zip file he opened in InteliJ 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 adds DB schema and DB data by adding the corresponding SQL files in the resources folder.

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

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

Next, he addresses observability: “I cannot tell if 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

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

Now that the application is production ready it is time to take it to production and buildpacks.io will do that to any type of package of your application (regardless of packaging or programming language). The other necessary thing to be done is to make the application as efficient and small as possible reminding that Java is an efficient technology and that garbage collection and the JIT do a good job to keep 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 for you. In his humoristic seriosity, Long mentioned that as he feels 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 is done.

As the service was done, he shifted focus to implementing a client that consume the implemented service. During the implementation, he showcased the new @GetExchange which is the client-side equivalent of @GetMapping from the server side. Initially, you could’ve found it in parts of Spring Cloud, but now it is part of the 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 but also with the newly added support for native compilation.

About the Author

Subscribe for MMS Newsletter

By signing up, you will receive updates about our latest information.

  • This field is for validation purposes and should be left unchanged.