Simple and scalable starter-kit to build powerful and organized REST projects with Spring Boot.
- Logging
- IP-based Rate Limiting using TokenBucket
- En/decrypt ENV variables
- Secure APIs using HTTPS
- Exception Handling
- Organize custom error codes for consistency, clarity, and easy debugging
- JDK: 21
- Maven: 3.9.9
- Spring: 3.5.x
- Spring Boot
- Spring Web
- Spring Validation
- Spring Security with JWT
- Spring Data JPA
- MySQL: 8.4
- Lombok: 1.18
- Spring Boot Modules:
- Spring Web (for REST APIs)
- Spring Validation (for input validation)
- Spring Security (with JWT for authentication)
- Spring Data JPA (with MySQL for datasource)
- Other Libs:
Run the application locally, pass jasypt.encryptor.password
as Spring Boot Property.
Use GitBash if you are on Windows.
mvn clean spring-boot:run -Dspring-boot.run.arguments="--jasypt.encryptor.password=encryption-password"
Note: When accessing these URLs in development, you might see certificate warnings in your browser due to self-signed certificates. This is expected, and you can proceed safely for development purposes.
Jasypt ensures sensitive configuration values like database credentials and API keys are securely encrypted.
- Add properties to be encrypted in
application.properties
withDEC(value-here)
- Run the provided encrypt command to replace all
DEC(...)
values with their encrypted form
Use GitBash if you are on Windows.
mvn jasypt:encrypt -Djasypt.plugin.path=file:src/main/resources/application-dev.properties -Djasypt.encryptor.password=encryption-password
Decrypt credentials that are wrapped with ENC(value)
in application.properties file.
Use GitBash if you are on Windows.
mvn jasypt:decrypt -Djasypt.plugin.path=file:src/main/resources/application-dev.properties -Djasypt.encryptor.password=encryption-password
Which would output the decrypted contents to the screen, rather than editing the file in place.
Run the Spring Boot application by passing the private key password as VM arguments in the command prompt like this:
java -jar target/your-application.jar -Djasypt.encryptor.password=encryption-password
Swagger provides a user-friendly interface for interacting with your REST endpoints during development.
Structured the app with layered architecture to be modular, testable and scalable. Can adjust base on specific project needs.
com.nyanmyohtet.springbootstarter
│
├── api/rest // REST controllers
├── service // Business logic
├── repository // Data access logic (Spring Data JPA, etc.)
├── model // Domain models/entities
├── dto // Data Transfer Objects
├── config // Configuration classes (security, caching, etc.)
├── exception // Custom exceptions and handlers
├── util // Utility or helper classes
└── SpringBootApplication.java // Main entry point
- Controller Layer: Handles incoming HTTP request and map them to services.
- Service Layer: Contains business logic, avoid placing logic in controller.
- Repository Layer: Manages database interactions, usually using Spring Data JPA.
- Model Layer: Defines the structure of the data.
- DTOs (Data Transfer Object): Defines data structure for communication between parties(e.g., client and server).
The config
package hold:
application.properties
,application-<profile>.properties
: define externalized configurations.- Security: Spring Security setup.
- Scheduler: Scheduler config.
- Custom beans: defines beans for service wiring, third-party libs, etc.
- Place custom exceptions in
exception
package. - use
@RestControllerAdvise
for centralized exception handling for REST endpoints.
- Place tests in
src/test/java
with the same package structure as main code. - Use JUnit 5 for testing, MockMvc for controller tests and Mockito for mocking dependencies.