Skip to content

jssaggu/springboot-tutorial

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SpringBoot Tutorial

Java Maven CI

A comprehensive Spring Boot tutorial project demonstrating various Spring Boot features and best practices.

Video Tutorials

All tutorial videos are available on the Saggu.uk YouTube channel.

Watch the video

Table of Contents

Prerequisites

  • Java 17 or later
  • Maven 3.6+
  • Docker (optional, for running Redis and databases)
  • IDE (IntelliJ IDEA recommended)

Getting Started

  1. Clone the repository:
git clone https://github.com/jssaggu/springboot-tutorial.git
cd springboot-tutorial
  1. Build the project:
mvn clean install -DskipTests
  1. Run the application:
mvn spring-boot:run

Project Structure

src/
├── main/
│   ├── java/          # Java source code
│   ├── resources/     # Configuration files
│   └── docker/        # Docker configuration
└── test/             # Test files

Features

Spring Profiles

Spring profiles allow you to configure different environments (dev, prod, test) for your application.

How to run using a profile?

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=8080

Or using the JAR:

java -jar target/springboot-tutorial-0.0.1-SNAPSHOT.jar --server.port=8080 --management.server.port=9090

Spring Caching

The project supports multiple caching providers. Note: Enable only one cache provider at a time.

Redis Cache

  1. Add the dependency:
<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-data-redis</artifactId>
    <version>${cache.version}</version>
</dependency>
  1. Configure in application.yml:
spring:
  cache:
    redis:
      time-to-live: 100S
    type: redis
  1. Run Redis using Docker:
docker pull redis
docker run --name saggu.uk -p 6379:6379 -d redis

Hazelcast Cache

  1. Add the dependency:
<dependency>
    <groupId>com.hazelcast</groupId>
    <artifactId>hazelcast-all</artifactId>
    <version>4.2.4</version>
</dependency>
  1. Add hazelcast.yaml:
hazelcast:
  network:
    join:
      multicast:
        enabled: true

Database Migration (Flyway)

Using Maven

For H2:

mvn clean -Dflyway.configFiles=src/main/docker/flyway-h2.conf -Dflyway.locations=filesystem:src/main/resources/db/migration/ flyway:migrate

For 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

Available Flyway Commands

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

Database Connection

H2 Database
  • URL: jdbc:h2:file:./springboot-tutorial/target/foobar
  • Username: sa
  • Password: (empty)
Using Docker

Run the following command from the src/main/docker directory:

docker compose up -d

Development

IDE Setup

For IntelliJ IDEA:

  1. Open the project
  2. Import as Maven project
  3. Enable annotation processing
  4. Configure H2 database connection as described above

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

About

SpringBoot Tutorial by Saggu.UK

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Contributors 3

  •  
  •  
  •  

Languages