Skip to content

hieubz/spring-boot-template-project

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

88 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Spring Boot Template Project

Thanks to my brothers SonPM, DatDD, LinhPH.

Overview

Whenever I need to implement a new feature, I typically start by researching available solutions on Google. Then I will experiment with one or more solutions to select the best one. However, after several months, I might forget how to implement that feature. Consequently, I end up having to revisit internet resources, conduct research once again, and reattempt the implementation.

Google_Search

The above situation is very common, not just for me but also among my friends and colleagues. We waste a lot of time recalling and researching solutions - things could be synthesized in a template project for the next implementation.

So I have developed this project which includes implementations designed to assist both myself and other Spring Boot developers in seamlessly diving into coding. Each commit within the project represents the implementation of a specific technique.

The project uses Java 17 and Spring Boot 3.1.5.

If you find this project useful, please give it a star ⭐️!

Architecture

I designed the project with 4 main components:

.
├── application               # Controllers, passing user requests into services respectively
├── core                      # Domain logic, designed into services
├── infrastructure            # Config, repository, third parties,...
└── shared                    # Constants, DTO, utils,...

And we have a main flow as shown below:

Raw Design

Features

Authen/Authorization

  • Fixed Token Authentication
  • JWT Authentication
  • Session based Authentication
  • Authorization

Web Basics

  • Basic REST API
  • Spring JDBC, Spring JPA
  • Pagination
  • MDC logging
  • Exception Handling
  • Jackson & JSR310
  • REST client with OpenFeign
  • SOAP client with JAXB
  • Background Job
  • Retry
  • ActiveMQ and Spring JMS Integration
  • Export XLSX/CSV reports
  • CORS configuration
  • Swagger

Advanced Techniques

  • Caching with Redis
  • Caching Local with Caffeine
  • Multiple Cache Manager
  • MultiThread, Async
  • Event Handling
  • Race Condition Handling (Redis/MongoDB Lock)
  • Distributed Transactions
  • Kafka Producer/Consumer (Json, Avro)
  • Search Backend with Elasticsearch
  • Generate and send emails
  • Rate Limiter with Bucket4j
  • Circuit Breaker, Rate Limiter with Resilience4j
  • Distributed Tracing with Micrometer and Zipkin

Datasource

  • Multiple DataSource Configuration
  • Read/Write Splitting

Unit Test

  • Unit Test common cases (with Junit 4, Mockito, PowerMock)
  • Integrate Jacoco for Code Coverage

Monitoring

  • Monitoring with Actuator & Prometheus
  • Sentry Integration

How to use

Firstly, clone it to your local and open by your IDE (IntelliJ, Eclipse).

Each commit will be a feature except update README.md commits. For example, you can search on IntelliJ (Git tab) by feature keywords:

img_2.png

Then you can apply the code of the corresponding commit for your feature.

Setup

To run this project (optional for new guys, minimum 16GB RAM if you want to run local Elasticsearch)

  • Download and install IntelliJ IDEA (Recommends)

  • Install Docker and Docker Compose if you don't have your own database and message brokers

  • Run git clone https://github.com/hieubz/spring-boot-based-project.git

  • Configure JDK 11/17 for your project on IntelliJ IDEA

  • Run docker-compose up -d to start MySQL, MongoDB, Redis, Kafka, ActiveMQ and Elasticsearch (or update your database configs in application.properties)

    Notes: Elasticsearch container requires much RAM on local

  • Run resources/schema/mysql-schema.ddl to initialize your MySQL database.

  • Run commands in resources/schema/mongo-schema.ddl to initialize your MongoDB database.

  • Run your DemoApplication and check Swagger UI: http://localhost:8080/swagger-ui/index.html#/

Tools

Redis Commander (for Linux only)

  • Install Redis Commander as your Redis client
  • Run redis-commander --redis-db 10 --redis-password 123 (depends on your db/password config)
  • Check your Redis Commander UI: http://127.0.0.1:8081

DataGrip

  • I recommend using DataGrip to work with MySQL, MongoDB, Redis

Releases

No releases published

Packages

No packages published