A comprehensive Spring Boot tutorial project demonstrating various Spring Boot features and best practices.
All tutorial videos are available on the Saggu.uk YouTube channel.
- Java 17 or later
- Maven 3.6+
- Docker (optional, for running Redis and databases)
- IDE (IntelliJ IDEA recommended)
- Clone the repository:
git clone https://github.com/jssaggu/springboot-tutorial.git
cd springboot-tutorial- Build the project:
mvn clean install -DskipTests- Run the application:
mvn spring-boot:runsrc/
├── main/
│ ├── java/ # Java source code
│ ├── resources/ # Configuration files
│ └── docker/ # Docker configuration
└── test/ # Test files
Spring profiles allow you to configure different environments (dev, prod, test) for your application.
mvn spring-boot:run -DskipTests -Dspring-boot.run.profiles={Profile-Name}Examples:
- For Dev profile:
mvn spring-boot:run -DskipTests -Dspring-boot.run.profiles=dev- For different ports:
mvn spring-boot:run -Dspring-boot.run.arguments=--server.port=8080Or using the JAR:
java -jar target/springboot-tutorial-0.0.1-SNAPSHOT.jar --server.port=8080 --management.server.port=9090The project supports multiple caching providers. Note: Enable only one cache provider at a time.
- Add the dependency:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-data-redis</artifactId>
<version>${cache.version}</version>
</dependency>- Configure in
application.yml:
spring:
cache:
redis:
time-to-live: 100S
type: redis- Run Redis using Docker:
docker pull redis
docker run --name saggu.uk -p 6379:6379 -d redis- Add the dependency:
<dependency>
<groupId>com.hazelcast</groupId>
<artifactId>hazelcast-all</artifactId>
<version>4.2.4</version>
</dependency>- Add
hazelcast.yaml:
hazelcast:
network:
join:
multicast:
enabled: trueFor H2:
mvn clean -Dflyway.configFiles=src/main/docker/flyway-h2.conf -Dflyway.locations=filesystem:src/main/resources/db/migration/ flyway:migrateFor PostgreSQL:
mvn clean -Dflyway.configFiles=src/main/docker/flyway-postgres.conf -Dflyway.url=jdbc:postgresql://localhost:5432/postgres -Dflyway.locations=filesystem:src/main/resources/db/migration/ flyway:migrate| Command | Description |
|---|---|
| migrate | Migrates the database |
| clean | Drops all objects in the configured schemas |
| info | Prints the details and status information about all the migrations |
| validate | Validates the applied migrations against the ones available on the classpath |
| undo | Undoes the most recently applied versioned migration (Flyway Teams) |
| baseline | Baselines an existing database, excluding all migrations up to and including baselineVersion |
| repair | Repairs the schema history table |
- URL:
jdbc:h2:file:./springboot-tutorial/target/foobar - Username:
sa - Password: (empty)
Run the following command from the src/main/docker directory:
docker compose up -dFor IntelliJ IDEA:
- Open the project
- Import as Maven project
- Enable annotation processing
- Configure H2 database connection as described above
Contributions are welcome! Please feel free to submit a Pull Request.
