Thanks to my brothers SonPM, DatDD, LinhPH.
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.
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 ⭐️!
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:
- Fixed Token Authentication
- JWT Authentication
- Session based Authentication
- Authorization
- 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
- 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
- Multiple DataSource Configuration
- Read/Write Splitting
- Unit Test common cases (with Junit 4, Mockito, PowerMock)
- Integrate Jacoco for Code Coverage
- Monitoring with Actuator & Prometheus
- Sentry Integration
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:
Then you can apply the code of the corresponding commit for your feature.
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#/
- 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
- I recommend using DataGrip to work with MySQL, MongoDB, Redis