This project demonstrates a simple Spring Boot application containerized with Docker. It serves a "Hello World" message
in the "/" route, and a JSON list of items in the "/items" route.
src
├── main
│ ├── java
│ │ └── com
│ │ └── example
│ │ └── demo
│ │ ├── DemoApplication.java
│ │ ├── controller
│ │ │ └── ItemController.java
│ │ ├── service
│ │ │ └── ItemService.java
│ │ ├── dao
│ │ │ └── ItemDao.java
│ │ └── entity
│ │ └── Item.java
│ └── resources
│ └── application.properties
├── Dockerfile
└── pom.xml
- Java JDK 17 or later
- Maven
- Docker
-
Clone this repository:
git clone <repository-url> cd <project-directory>
-
Build the Spring Boot application:
mvn clean package
-
Build the Docker image:
docker build -t springboot-demo . -
Run the Docker container:
docker run -p 8090:8090 springboot-demo
- Hello World message: http://localhost:8090/
- List of items: http://localhost:8090/items
DemoApplication.java: The main Spring Boot application class.ItemController.java: REST controller that handles HTTP requests.ItemService.java: Service layer for business logic.ItemDao.java: Data Access Object for retrieving item data.Item.java: Entity class representing an item.application.properties: Configuration file for Spring Boot.Dockerfile: Instructions for building the Docker image.
The application is configured to run on port 8090. This can be changed in the application.properties file:
server.port=8090
Remember to update the Dockerfile and Docker run command if you change the port.
If you encounter any issues, ensure that:
- The required ports are not in use by other applications.
Most of the time, port 8080 will be in use by other applications such as PostgreSQL, MySQL, etc.
- You have the necessary permissions to run Docker commands.
- Your Java and Maven versions are compatible with the project.