Skip to content

rozuur/spring-boot-opinionated

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

30 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

spring-boot-opinionated

An opinionated setup of spring boot application

Java

Uses Java 11

Docker

Distroless is the base image.

As java is object-compatible, docker image is generated by copying the packaged jar. This is preferred over multi-stage docker, as multi-stage docker downloads internet

To build and run the application at port 8080 use docker run --rm -it -p8080:8080 $(docker build -q .)

Local Development

Start the application at port 8080 and debug port 5005 using mvn spring-boot:run -Dspring-boot.run.jvmArguments="-Xdebug -Xrunjdwp:transport=dt_socket,server=y,suspend=n,address=5005"

Code is auto formatted during compilation using formatter-maven-plugin and impsort-maven-plugin.

maven-enforcer-plugin is used to enforce java and mvn versions.

Database

Liquibase is used for database changes. SQL changes are present at src/main/resources/db/changelog

For testing, liquibase is disabled and h2 is used. Database entities are generated from classes instead of running changelog scripts.

Swagger

Swagger is exposed at /swagger-ui.html

REST API

APIs are exposed with a prefix, here it is /api/v1

APIs returns data transfer objects instead of entities, to reduce coupling of models to database schema.

POST APIs should return 201 Created with inserted resource PUT APIs should return updated resource

Actuator

actuator/health/readiness is health check endpoint for load balancer

actuator/health shows health stats

actuator/info API exposes git state through git-commit-id-plugin

actuator/prometheus API exposes metrics

actuator/loggers Used for changing log levels in runtime

Static Analysis

Following plugins are used for static analysis

  1. maven-pmd-plugin
  2. spotbugs-maven-plugin
  3. modernizer-maven-plugin

Testing

maven-surefire-plugin runs tests through maven.

jacoco-maven-plugin is used for code coverage

Release

mvn deploy fails if local modifications are present using maven-scm-plugin

maven-release-plugin is used in tools/jenkins_build.sh for release

maven-deploy-plugin is used for deploying to nexus repository if required

TODO

  1. Integrate Caching
  2. Integrate OAuth