Spring Boot Boilerplate is a starter kit designed to help you quickly get started with building a Spring Boot application. This project provides a simple and useful template that incorporates various essential technologies and configurations.
- Spring Boot (v2.7.10): Simplifies the development of Spring applications.
- Spring Data JPA: Provides easy integration with relational databases using JPA.
- Spring Validation: Handles validation of Java Beans.
- Spring Security + JWT Token: Secures your application with JWT-based authentication.
- PostgreSQL: A powerful, open source object-relational database system.
- MapStruct: A code generator that simplifies the mapping of Java Beans.
- Lombok: Reduces boilerplate code for model objects by generating getters, setters, and other methods.
- Swagger (Open API): Provides interactive API documentation.
The project follows a standard Maven project layout:
spring-boot-boilerplate
├── src
│ ├── main
│ │ ├── java
│ │ │ └── com/gdsc/boilerplate/springboot
│ │ │ ├── configuration
│ │ │ ├── controller
│ │ │ ├── dto
│ │ │ ├── exception
│ │ │ ├── mapper
│ │ │ ├── model
│ │ │ ├── repository
│ │ │ ├── security
│ │ │ ├── service
│ │ │ ├── utils
│ │ │ └── SpringBootBoilerplateApplication.java
│ │ └── resources
│ │ ├── application.yml
│ │ └── static
│ └── test
│ └── java
│ └── com/gdsc/boilerplate/springboot
└── pom.xml
You can customize the JWT token information such as secret key, issuer, and expiry date in the application.yml file.
jwt:
secret: your_secret_key
issuer: your_issuer
expiry: 86400000 # in milliseconds
You can customize the database connection information in the application.yml file.
spring:
datasource:
url: jdbc:postgresql://localhost:5432/your_db
username: your_username
password: your_password
driver-class-name: org.postgresql.Driver
jpa:
hibernate:
ddl-auto: update
show-sql: true
You can customize Swagger settings in the application.yml file.
swagger:
enabled: true
title: Spring Boot Boilerplate API
description: API documentation for the Spring Boot Boilerplate project
version: 1.0.0
contact:
name: Your Name
url: http://your-url.com
email: [email protected]
You can customize which endpoints are accessible without token information in the SecurityConfiguration.java file.
public SecurityFilterChain securityFilterChain(HttpSecurity http) throws Exception {
return http.cors().and().csrf(csrf -> csrf.disable())
.addFilterBefore(jwtAuthenticationFilter, UsernamePasswordAuthenticationFilter.class)
.authorizeRequests(requests -> requests
.antMatchers("/register", "/login", "/v3/api-docs/**", "/swagger-ui/**", "/api-docs", "/actuator/**").permitAll()
.anyRequest().authenticated())
.exceptionHandling(handling -> handling.authenticationEntryPoint(unauthorizedHandler))
.sessionManagement(management -> management.sessionCreationPolicy(SessionCreationPolicy.STATELESS)).build();
}
- Docker: Make sure Docker is installed and running.
- Java: Ensure you have Java 11 or higher installed.
- Maven: Make sure Maven is installed.
If you're using Docker, you can use the following command to start the containers in detached mode:
docker-compose up -d
Navigate to the root of the project and run the following command to build the project:
mvn clean install
Navigate to the target directory and run the application:
java -jar target/spring-boot-boilerplate.jar
Once the application is running, you can access the Swagger UI at:
http://localhost:8080/api-docs
https://gdsc-boilerplate-swagger-docs-api-latest.onrender.com/
This provides interactive documentation for your API endpoints.
This project is licensed under the Apache License 2.0. See the LICENSE file for details.