A modern Spring Boot 3.3.5 REST API template with MongoDB integration, JWT authentication, and Swagger UI documentation.
Ravindra Valand (RV)
- Features
- Tech Stack
- Prerequisites
- Getting Started
- Environment Setup
- API Documentation
- Project Structure
- Development
- Security
- Contributing
- 🔐 JWT Authentication & Authorization
- 📝 MongoDB Integration
- 📚 Swagger UI Documentation
- 🔄 Auto-reload during development
- 🛡️ Spring Security Configuration
- 🎯 RESTful API endpoints
- ⚡ CRUD Operations
- 📊 User & Product Management
- Java 21
- Spring Boot 3.3.5
- Spring Security
- MongoDB
- Gradle
- JWT
- SpringDoc OpenAPI (Swagger UI)
- Lombok
- Spring Boot DevTools
- Java 21 or higher
- MongoDB 6.0 or higher
- Gradle 8.x
- IDE (IntelliJ IDEA recommended)
- Git
- Postman (for API testing)
git clone https://github.com/ravindra-valand/spring-boot-mongodb-template.git
cd spring-boot-mongodb-template
- Copy the example properties file:
cp src/main/resources/application-example.properties src/main/resources/application.properties
- Update the following properties in
application.properties
:
# MongoDB Configuration
spring.data.mongodb.host=localhost
spring.data.mongodb.port=27017
spring.data.mongodb.database=your_database_name
# JWT Configuration
jwt.secret=your_secret_key
jwt.expiration=86400000
# Server Configuration
server.port=8080
spring.profiles.active=dev
# Build the project
./gradlew clean build
# Run with auto-reload enabled
./gradlew bootRun
The application will start on http://localhost:8080
- Install IntelliJ IDEA (Community or Ultimate)
- Install the following plugins:
- Lombok
- Spring Boot Assistant
- MongoDB Plugin
- Enable annotation processing:
- Go to Settings → Build, Execution, Deployment → Compiler → Annotation Processors
- Check "Enable annotation processing"
- Install MongoDB Community Edition
- Start MongoDB service:
# Windows
net start MongoDB
# macOS/Linux
sudo systemctl start mongod
- Verify connection:
mongosh
- Import code style settings:
- Go to Settings → Editor → Code Style
- Import the
codestyle.xml
from the project root
# Run all tests
./gradlew test
# Run specific test class
./gradlew test --tests "com.portglint.first.YourTestClass"
Swagger UI is available at: http://localhost:8080/swagger-ui/index.html
- Auth
- POST
/api/auth/register
- Register new user - POST
/api/auth/login
- Login and get JWT token
- POST
- Users
- GET
/api/users
- Get all users - GET
/api/users/{id}
- Get user by ID - PUT
/api/users/{id}
- Update user - DELETE
/api/users/{id}
- Delete user
- GET
- Products
- GET
/api/products
- Get all products - GET
/api/products/{id}
- Get product by ID - POST
/api/products
- Create new product - PUT
/api/products/{id}
- Update product - DELETE
/api/products/{id}
- Delete product
- GET
src/main/java/com/portglint/first/
├── config/ # Configuration classes
├── controller/ # REST controllers
├── model/ # Domain models
├── repository/ # MongoDB repositories
├── service/ # Business logic
├── security/ # Security configurations
└── Application.java
Enable auto-reload:
- Add Spring Boot DevTools dependency
- Configure your IDE for auto-build
- Run with
./gradlew bootRun
- JWT-based authentication
- Password encryption using BCrypt
- Role-based authorization
- Secured endpoints
- Fork the repository on GitHub
- Clone your fork locally:
git clone https://github.com/YOUR-USERNAME/spring-boot-mongodb-template.git
- Add the upstream repository:
git remote add upstream https://github.com/ravindra-valand/spring-boot-mongodb-template.git
- Create a new branch:
git checkout -b feature/your-feature-name
- Keep your branch updated:
git fetch upstream
git rebase upstream/main
- Make your changes and commit:
git add .
git commit -m "feat: add amazing feature"
- Push changes to your fork:
git push origin feature/your-feature-name
- Create a Pull Request through GitHub
Follow conventional commits format:
feat:
for new featuresfix:
for bug fixesdocs:
for documentationstyle:
for formatting changesrefactor:
for code refactoringtest:
for adding testschore:
for maintenance tasks
- All PRs must be reviewed by at least one maintainer
- Address review comments and update PR
- Ensure all checks pass
- Squash commits before merging
- Write unit tests for new features
- Ensure all existing tests pass
- Add integration tests when necessary
- Maintain test coverage above 80%
-
MongoDB Connection Issues:
- Verify MongoDB is running
- Check connection string in properties
- Ensure correct credentials
-
Build Failures:
- Clean and rebuild:
./gradlew clean build
- Check Java version:
java -version
- Verify Gradle version:
./gradlew -v
- Clean and rebuild:
-
JWT Token Issues:
- Verify secret key configuration
- Check token expiration settings
- Ensure proper token format in requests
This project is licensed under the MIT License - see the LICENSE file for details.
Created with ❤️ by Ravindra Valand (RV)