Developing Spring Boot Applications with Choreo

Yomal Indula Perera
Choreo Tech Blog
Published in
7 min readFeb 13, 2024

--

Photo by Arnold Francisca on Unsplash

Spring Boot is an open-source Java framework designed to facilitate the creation of stand-alone, production-grade Spring applications. Whether you’re developing a RESTful API, a microservice, or a batch task, Spring Boot simplifies the process. While platforms like Microsoft Azure and Amazon Web Services (AWS) offer cloud deployment options for Spring Boot applications, Choreo provides specialized features and tools tailored specifically for Spring Boot, streamlining deployment and management. If you’re seeking a platform that simplifies the deployment and maintenance of Spring Boot apps in the cloud, Choreo, a robust internal developer platform, is an ideal solution.

Choreo boasts several features that facilitate the deployment and management of Spring Boot applications, including:

  • Source to deployment with automated CI/CD pipelines
  • API Management and Monitoring

In this tutorial, you will learn how to :

  • Create a containerized service component that is dynamically provisioned from a GitHub repository containing Spring Boot application code.
  • Deploy the service component to the development environment using a CI/CD pipeline.
  • Test the service.
  • Promote the service to the production environment.
  • Monitor the service.

The sample Spring Boot application used for this tutorial has 5 different REST API endpoints tailored to interact with a Book database. The application exposes five endpoints, utilizing various HTTP methods to interact with a database of books:

  • GET /books: Retrieves a list of all books in the database.
  • GET /books/{id}: Retrieves a specific book identified by its unique ID.
  • POST /books: Creates a new book and adds it to the database.
  • PUT /books: Updates an existing book identified by its ID provided in the request body.
  • DELETE /books/{id}: Deletes a specific book from the database.

Prerequisites:

  1. A Choreo account.
  2. A GitHub account with the forked repository of the sample source code.

Step 1: Create a containerized service component:

  1. Go to https://console.choreo.dev/, and sign in.

2. If you already have one or more components in your project, click + Create else , proceed to the next step.

3. Click the Service card.

4. Provide a display name and description for your service component in the Create a Service page.

5. Next click Authorize with GitHub under the Connect Your Repository section to allow Choreo to connect to your GitHub account.

(Alternatively if you have not forked the repository provided in the Prerequisites section above, insert https://github.com/wso2/choreo-samples in the Provide Repository URL field.)

6. Enter the following information:

7. Click Create.

Step 2: Deploy the service in the development environment:

  1. In the Component view, navigate to the Build tab in the left navigation menu.

2. In the Build page you will see information about the source repository, branch and Build Configurations section which can be edited as required. Click the Build Latest button at the top right of the Builds card.

This will launch a view that to initiate the Choreo Generated Build Action. Wait until the build action is completed as shown below.

4. Navigate to the Deploy tab in the left navigation menu. Information about the deployment status of the component in different environments can be seen in this view. You can also add configurations(if any) to your build image at deployment. Make sure your build from the previous step is selected in the Image section and click Configure & Deploy.

5. The first step in the view that appears is setting Environment Variables which can be configured as per your requirement. Click Next.

6. The next step is File Mount where you can add a Config File if required. Then click Next.

7. Next the Endpoints details which are extracted from the endpoints.yaml file in the GitHub repository are displayed. Review the specified details and confirm before pressing the Deploy button.

This will deploy your component and it should be successfully deployed to the Development environment.

Step 3: Testing the deployed service:

Now that our Spring Boot application is deployed and ready to be used, it’s time to verify its functionality. We’ll focus on testing two key endpoints: the GET method for retrieving books and the POST method for creating new books.

  1. Click Test in the left navigation menu and then click Console. This opens the OpenAPI Console pane.

2. Expand the GET endpoint from the endpoint list.

3. Click Try it out.

4. Click Execute. You can see the response body under the Responses section.

5. Next expand the POST endpoint and click Try it out.

6. You can see an example schema under the Request body section. Edit the values as you wish and click Execute.

7. You should see the entered Request body details in the Response body section with 200 response code as below.

8. Next go back to the GET endpoint section and press execute again. You should see your newly added book in the Response list.

Step 4: Monitoring and Observability features:

  1. Click Observability in the left navigation menu. You will see a view of your application’s logistics(Throughput and Latency).

These information can be filtered on factors such as:

  • Deployment Track/Branch
  • Environment
  • Time/ Time Zone

Below the graph view, we can see the Logs panel which shows live logs of the deployed Spring Boot application.

This panel includes all logs generated by the service. You can filter it based on time or text.

The Diagnostics View tab will show a view that is a graphical representation of the performance of an application over time. The graph represents the timeline, and different metrics, such as error rate, latency, CPU usage, and memory usage. The logs of the application are also displayed in the timeline.

The diagnostics view can be used to identify performance problems in an application. For example, if the error rate is increasing over time, this may indicate a problem with the application's code. If the latency is increasing over time, this may indicate a problem with the application's infrastructure. By analyzing the diagnostics view, developers can identify and fix performance problems in their applications.

Conclusion:

In conclusion, this tutorial has shown you how to use Choreo to build and deploy a Spring Boot application to the cloud. You have learned how to create a Choreo project, deploy the application to the cloud, and monitor the application's performance and availability.

Choreo is a powerful platform that makes it easy to deploy and maintain Spring Boot applications in the cloud. It provides a number of features that make it a good choice for cloud deployments, such as:

  • Automatic provisioning of resources
  • Centralized management and monitoring
  • Multi-environment support

Want to deploy and maintain your Spring Boot applications in the cloud with ease? Try out Choreo today! It's a powerful platform that makes it simple to deploy, manage, and monitor your applications across a variety of cloud platforms. With Choreo, you can focus on building great applications, and let us worry about the rest.

Sign up for free today and see how Choreo can help you take your Spring Boot applications to the next level.

--

--