Home United States USA — software Native-image With Spring Boot

Native-image With Spring Boot

125
0
SHARE

Learn how Spring is embracing the serverless, cloud-native world with Native-image in this Kotlin-based porgram.
Join the DZone community and get the full member experience. The Cloud has enabled a lot of new usages that were not possible before. Among them stands Serverless: Serverless computing is a cloud computing execution model in which the cloud provider allocates machine resources on demand, taking care of the servers on behalf of their customers. Serverless computing does not hold resources in volatile memory; computing is rather done in short bursts with the results persisted to storage. When an app is not in use, there are no computing resources allocated to the app. — Wikipedia Likewise, to manage the risk of lock-in with the walled garden of a single Cloud vendor, one can eschew their specific services and choose Kubernetes. In both cases, and especially in the former, the lifetime of the pod/container is short. Therefore, startup time has a significant impact on the performance of the system as a whole. It’s clearly a domain where the JVM doesn’t shine. To cope with this, Oracle provides GraalVM, which contains a bytecode-to-binary AOT compiler. I’ve been following GraalVM’s improvements over several versions, standalone and integrated with Spring Boot. The Spring framework was designed more than a decade ago when this concern was absent. On the other hand, a couple of years ago saw the birth of Spring competitors who embraced the Cloud and AOT: Micronaut and Quarkus. In this three-part series, I want to have a look at each of them in turn, dissecting a couple of themes: For that, I’ll create a Kotlin-based application that can query the Marvel API using non-blocking code. This post is dedicated to explaining the application and Spring Boot. Marvel offers a REST API to query their data. It requires the generation of an API key and a private key. To authenticate, one needs to pass the following as query parameters: For more detailed information, please refer to the documentation. The Spring team was the first to offer a Web UI to configure one’s project, the Spring Initializr. With it, you can configure the following parameters: Additionally, the application also offers a REST API to use the CLI and automate repetitive tasks. IntelliJ IDEA integrates the REST API, so you can create a new project while not leaving your IDE. Finally, while it’s hosted, the underlying code is available on GitHub under the Apache v2 license so that you can clone and configure it. It’s designed with extensibility in mind to allow for upgrades. I’ve already written a dedicated post on the different ways one can create beans in Spring. Though Spring has a dedicated DSL for beans, we will use the “traditional” way – annotations. We need an MD5 message-digest to authenticate. With the Bean DSL, we can configure one like this: Spring will automatically discover this class at startup time thanks to the @SpringBootApplication annotation, and instantiate the beans: Spring was the first to introduce the annotation-based controller configuration on top of the Servlet API.

Continue reading...