I have been working on Java spring boot for more than a year now. And whenever I start a new project I find myself repeating so many steps while doing so. I have been thinking of create a spring boot boilerplate code generator for me to save me from repeating common steps. But wasn’t able to find enough time until recently. I am sharing this generator so that it can be used by others if needed.
What I have done
It is very simple for now. I generated a spring boot project from spring initializer and added all the files and configuration that I commonly do in all my projects. I have also written a shell script that does the following:
- Copies the boilerplate code into a new project
- Updates artifact id, package name and project name in the new project as per my requirement
I plan to enhance this spring boot boilerplate generator to take other information like java version, spring boot version and dependencies from configuration file. For now it does exactly what I need it for.
Boilerplate Code Included
- Health check controller
- Request logger filter for request logging (Read: Logging in Spring Boot with MDC)
- Web security configuration with user definition for securing swagger UI and other swagger urls
- Swagger configuration with API security in headers (Read: Spring boot swagger with authentication)
- AppProperty class for managing and accessing property values
- RestTemplate bean definition
- Logback.xml
Dependencies Included
- Spring Data JPA
- Dev Tools
- Spring Starter Web
- Spring Starter Security
- MySql Connector
- Lombok
- HttpClient
- Swagger UI (Secured)
- SpringFox Starter
How to use
- Clone the repository with spring boot boilerplate code and generator script:
- Update the file
config.dat
with your project properties:
project_name=new-spring-project
group_id=com.companyname
artifact_id=new-project
- Go to project directory and run
./initiazlie.sh
You should see an output like this:
The script will create a new project in the same directory as spring-boot-boilerplate
project, copy all the necessary files, update the project as per the data in config.dat
.
If your output is like the output in the image above, your new project should be running smoothly with swagger ui and you could just start developing your APIs.
Here is the link to github repo: https://github.com/abhibalani/spring-boot-boilerplate
Clone, Fork or Contribute. Drop a comment if you do any of these.