For further reference, please consider the following sections:
- Official Apache Maven documentation
- Spring Boot Maven Plugin Reference Guide
- Create an OCI image
- Spring Web
- Spring Boot Actuator
- Config Client Quick Start
- Eureka Discovery Client
- Spring Data JPA
- Spring HATEOAS
The following guides illustrate how to use some features concretely:
- Building a RESTful Web Service
- Serving Web Content with Spring MVC
- Building REST services with Spring
- Building a RESTful Web Service with Spring Boot Actuator
- Service Registration and Discovery with Eureka and Spring Cloud
- Accessing Data with JPA
- Building a Hypermedia-Driven RESTful Web Service
Due to Maven's design, elements are inherited from the parent POM to the project POM.
While most of the inheritance is fine, it also inherits unwanted elements like <license>
and <developers>
from the parent.
To prevent this, the project POM contains empty overrides for these elements.
If you manually switch to a different parent and actually want the inheritance, you need to remove those overrides.
This project utilizes a multi-stage Docker build to efficiently create the application image. Instead of copying the entire jar file, the Dockerfile selectively copies the necessary dependencies, libraries, and compiled classes. This approach optimizes the build process and reduces the image size. The following dependency should be added to use the docker in our application,
<plugin>
<groupId>com.spotify</groupId>
<artifactId>dockerfile-maven-plugin</artifactId>
<version>1.4.13</version>
</plugin>
- Use
mvn clean
command to remove all files generated by the previous build, such as the target directory. This ensures a fresh start for subsequent builds, eliminating any potential issues caused by leftover artifacts. - Use
mvn package
command which compiles the project and packages the compiled code into its distributable format, typically a JAR or WAR file, depending on the project's configuration. This step also includes running tests and placing the packaged output in the target directory. - Use
mvn dockerfile:build
command to build a Docker image for the application as specified in the Dockerfile. This command integrates Docker with Maven, automating the process of packaging the application into a Docker container. It typically uses the pluginspotify/dockerfile-maven-plugin
as mentioned above or a similar one, and after execution, a Docker image is created and ready for deployment or further use.
- Use
docker images
to display a list of all Docker images available on your local machine, providing key details such as the image repository name, tag (used to identify different versions), image ID (a unique identifier for each image), the date the image was created, and its size. This command is essential for managing local images, verifying successful builds, and ensuring you have the correct versions of images ready for deployment or other tasks. - Use
docker run <image_id>
command to create and start a container from a specified Docker image. When executed, it initializes a container based on the image and can include options to configure the container's behavior, such as port mapping (-p
), environment variables (-e
), volumes (-v
), and whether the container runs in the background (-d
). For example,docker run -d -p 8080:80 my-app
would start a container from themy-app
image, running it in detached mode and mapping port 8080 on the host to port 80 in the container. - Use
docker ps
command to display a list of currently running Docker containers, showing important details like the container ID, the image used to create the container, the command that initiated it, when the container was started, its current status, port mappings, and the container name. By default, it displays only active containers, but using the-a
option reveals all containers, including those that have stopped. This command is essential for monitoring and managing running containers. - Use
docker compose up
command to start or create all the services defined in adocker-compose.yml
file, bringing up containers, networks, and volumes as specified. It handles the orchestration of multiple containers, allowing them to interact according to the configuration.