Introduction to Spring Boot and JDBCTemplate: Introduction to Docker

Otavio Santana
xgeeks
Published in
3 min readApr 27, 2021

With the set application connected to the database, the next step is to deploy the application. In the third part of this series, our primary goal is to deploy our application using both Docker and Docker-compose resources.

Indeed, the use of containers has made the use and adoption of cloud computing a lot easier, and with its most significant differential, the application isolation refuse. Making an analogy with the Java world of which we have the WORA Write Once Read Anywhere with containers, we have the PORA Package Once Run Anytime. Since the container, on a general basis, focuses on being an isolated package within an application. The purpose of this article is not to talk about the inner workings of a container. However, we have this excellent article from Larry that manages to address more about the subject.

Within the microservices world, Leonard Richardson breaks down the principal elements of a REST approach into three steps. These introduce resources, HTTP verbs, and hypermedia controls. In the cloud computing environment, there is still no similar thing for the glory of the cloud. However, there is an excellent debate about some elements of migrating an application until the cloud computing environment arrives:

  1. Orchestrator: Once you work with containers and isolate applications, the next step would be to create mechanisms to manage such containers.
  2. CI/CD: A good code is a code in production, however, with the most outstanding possible security. The use of CI / CD tools helps in this regard.
  3. Infrastructure as code: Creates a declarative API for operations; this allows for greater integration and the implementation of the DevOps culture, in addition to the significant first step towards greater automation of processes.
  4. GitOps: Git becomes a source of truth for both code and operations.

The first step is to run the terminal application and then run the same application, however, with docker-compose. For the installation of the database, Docker will help straightforwardly. Thus, to start a PostgreSQL instance, it is necessary to execute with the following command:

The next step is to run the application; once we use maven, there is a command to prepare the application.

The application is running; feel free to perform tests within the application. It is missing API documentation such as Swagger and Open API, which we won’t cover.

The next step is to run this same application within the docker-compose; Spring has a maven plugin to create a Docker image integrated with Paketo.

After the build, there may be a new image with the version’s name according to the project in maven.

The next and last step is to create the docker-compose.yml file:

We present all the initial concepts to create an application locally or through the docker, through a plugin from Spring itself. With Spring JDBC, there was a significant reduction in code compared to JDBC of the core java. However, there are still tools that managed to reduce this complexity even more. In the third and last part of the series, there will be a refactoring to use the same problem using Spring Data JPA.

If you enjoy working at a large scale in projects with global impact and if you like a real challenge with Java, feel free to reach out to us at xgeeks! We are growing our team, especially in Java and you might be the next one to join this group of talented people 😉

Check out our social media channels if you want to get a sneak peek of life at xgeeks! See you soon!

--

--

Otavio Santana
xgeeks
Editor for

Empowering developers worldwide to deliver better software in the Cloud. Staff Eg xgeeksio