Production ready maven based Spring Boot starter kit application.
Starter kit for jump starting the development of a API oriented spring based Java server. It contains the best practices and latest tools that a spring boot developer should opt for in a fresh development. Since JPA is used, developers are free to opt for any SQL based DB engine for persistence (Postgres has been used as an example with this code sample). The preferred IDE for development is IntelliJ which comes with a plethora of useful JAVA tools to support Spring Boot development, but devlopers are free to opt for Eclipse or STS as well.
|____src | |____main | | |____java | | | |____com | | | | |____systango | | | | | |____springboard | | | | | | |____api | | | | | | | |____v1 | | | | | | | | |____controller | | | | | | | | |____request | | | | | | |____domain | | | | | | | |____model | | | | | | | | |____user | | | | | | | |____repository | | | | | | |____dto | | | | | | | |____model | | | | | | | | |____user | | | | | | | |____response | | | | | | |____mapper | | | | | | |____security | | | | | | |____service | | | | | | | |____admin | | | | | | | |____exception | | | | | | | |____user | | | | | | |____util | | |____resources | | | |____static | | | | |____css | | | | |____img | | | | |____js | | | |____templates | | | |____db | | | | |____migration | |____test | | |____java | | | |____com | | | | |____systango | | | | | |____springboard
Flyway library is integrated to manage database migrations. The migration files have to be kept in
src/main/resources/db/migration folder. There are sample migrations present here to depict file name patterns. Flyway will create a table in the database to manage the schema version files.
The pom.xml can be configured to generate a WAR or standalone executable jar file as well. We suggest developers should use JAR in the development environment as the hot swapping and live reload features in Spring Boot are compatible with it and for production deployment WAR packaging should be used with standalone Tomcat (or any other servlet container) server.
Springboard supports docker container out of the box. This framework is meant to cater to both web based applications as well as scalable micro services written in Java. The 'Dockerfile' supplied with this boilerplate does a basic job in terms of instructing which tomcat image to pick and how to deploy the war file to the container. Please follow the steps mentioned below in order to create and deploy the docker container from this installation -
docker build -t springboard .
docker run -p 8090:8090 springboard
Since we have not included a postgressql inside this container and are trying to connect to a database that is external to the container, you may need to enable the databsae to allow connections from foreign IP addresses which is disabled in case of default installations.
Some handy dcoker comammnds are listed below, we found them useful during the course of this development and thought its worth sharing.
docker rmi --force $(docker images -q)
docker rm $(docker ps -a -q)
docker exec -it <mycontainer> bash
Springboard comes with a handy set of unit test cases present in the 'SpringboardApplicationTests' class inside the test directory. The test cases are based on the fact that spring security is applied, the first thing you should do before accessing a protected url in the application is obtain a valid JWT token using the utility method provided in the test suite. Once you have the valid token, any protected url could be unit tested without any issues.
Swagger documentation is in-built in this starter-kit and can be accessed at the following URL -
The configuration for swagger are driven via com.systango.springboard.util.SwaggerConfig.java class that at present shows all the apis listed under the "com.systango.springboard.api.*"package. The JWT token should be presented inside the value input box as "Bearer token_goes_here". The authorization header for the REST APIs should be as follows -
curl -X GET \ http://localhost:8090/v1/about/faq \ -H 'Authorization: Bearer eyJhbGciOiJIUzUxMiJ9.eyJzdWIiOiJhZG1pbiIsImV4cCI6MTUxNTMyMjU4Mn0.RHex52JtZZt0lfaZc_sHdwU8auevcT9COJDxp6RbBBU1ZbCEc6bh4b2CxjA8TSgH7DkwWIbO6ISqpMuUXNcZwA' \ -H 'Cache-Control: no-cache' \
This project is licensed under the terms of the MIT license.