Skip to content

Spring Boot application with - Flyway migration, JWT authentication, Hibernate Envers Auditing, Hazelcast distributed caching, Docker Compose support. Checkout different releases for all features added to this application - https://github.com/chatterjeesunit/spring-boot-app/releases

Notifications You must be signed in to change notification settings

chatterjeesunit/spring-boot-app

Repository files navigation

Sample Spring Boot project

Releases

For more detailed step by step guide on how to build this app, please refer to the blogs on - http://sunitc.dev/tag/spring-boot/

How to run it

  • Pre-requisite (for first time run only)
    Create a folder for mysql volume mount
    mkdir -p ~/data/mysql8

  • Build
    ./gradlew clean build

  • Run via Docker Compose
    docker-compose up -d --build --scale application=2

Creating Dummy Data

  • Run SQL Script - scripts/Create_Dummy_Data.sql

Default Users for Login

Username Password ROLE
admin01@tw.com admin01@123# ADMIN
admin02@tw.com admin02@123# ADMIN
user01@tw.com welcome@123# USER

Sample APIS

1. API to get JWT Auth Token
curl --location --request POST 'dev-sandbox/api/v1/auth/token' \
--header 'Content-Type: application/json' \
--data-raw '{
    "userName": "admin01@tw.com",
    "password": "admin01@123#"
}'
2. API to get all customers (paginated)
curl --location --request GET 'dev-sandbox/api/v1/customer/?pageNum=0&pageSize=10' \
--header 'Authorization: Bearer <<REPLACE JWT TOKEN HERE>>'

In above code, replace the text <<REPLACE JWT TOKEN HERE>> with JWT token from Auth API

Troubleshooting

  • If after running Docker Compose, you are getting 404 on the APIs,
    • Restart ONLY the load-balancer container - sometimes this happens when loadbalancer starts before application server starts
    • Create an alias for localhost (127.0.0.1)
      • The reason for doing this is because we have configured the traefik loadbalancer using hostname dev-sandbox
      • So if you hit any api with host as localhost, it wont work with current configuration of traefik loadbalancer
      • Just open the following file /etc/hosts, and add following line at the end
        127.0.0.1 dev-sandbox
      • After this configuration, restart the application using
        docker-compose restart

To-Do

  • Add a wait-for script in Docker compose for following container dependencies
    • Loadbalancer - Depends on - Application
    • Application - Depends on - Database