Introduction to Spring Boot and JDBCTemplate: Introduction to Docker
In this tutorial, we'll cover the integration between Spring and Docker. It is an excellent step to move your application to the cloud.
Join the DZone community and get the full member experience.Join For Free
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:
- Orchestrator: Once you work with containers and isolate applications, the next step would be to create mechanisms to manage such containers.
- 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.
- 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.
- 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
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.
Opinions expressed by DZone contributors are their own.