Giter VIP home page Giter VIP logo

spring-boot-2-template's Introduction

Template for Spring Boot 2 application

Java CI with Maven Coverage Branches

Includes web-server on port 9080 with /api/v1/articles endpoint exposed. Supports CRUD set of operations and Read with pagination (see usage description below).

Prerequisites:

  • Maven 3
  • JDK 17

How to build:

mvn clean install

Build Docker image with application inside:

docker build ./ -t backend-template-app

Start application using a starting script:

Use run.bat script

Start application (vs in-memory DB H2) by running executable jar:

java -jar target/spring-boot-2-template-0.0.1-SNAPSHOT.jar \
 --spring.datasource.url=jdbc:h2:mem:testdb \
 --spring.datasource.username=sa \
 --spring.datasource.password=password \
 --spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect \
 --spring.datasource.driver-class-name=org.h2.Driver

Same thing but using Spring profile to determine properties:

java -jar target/spring-boot-2-template-0.0.1-SNAPSHOT.jar \
 --spring.profiles.active=dev

Start application (vs in-memory DB H2) using Maven:

mvn spring-boot:run -Dspring-boot.run.arguments="\
--spring.datasource.url=jdbc:h2:mem:testdb \
--spring.datasource.username=sa \
--spring.datasource.password=password \
--spring.jpa.properties.hibernate.dialect=org.hibernate.dialect.H2Dialect \
--spring.datasource.driver-class-name=org.h2.Driver"

Same thing but using Spring profile to determine properties:

mvn spring-boot:run -Dspring-boot.run.arguments=--spring.profiles.active=dev

Start application in Docker container (vs Postgres DB in Docker):

docker-compose up

Start application in Docker container (vs Postgres DB in Docker) with rebuild service image:

docker-compose up --build --force-recreate --no-deps

Link for quick check:

http://localhost:9080/api/v1/articles

Swagger documentation:

http://localhost:9080/swagger-ui/index.html

Useful CURL commands

New article addition:

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -d '{ "title": "Some tittle", "text": "Some text", "author": "Pushkin" }' -X POST http://localhost:9080/api/v1/articles

Get existing article:

curl -i http://localhost:9080/api/v1/articles/1

Update existing article:

curl -i -H "Accept: application/json" -H "Content-Type: application/json" -d '{ "title": "Another tittle" }' -X PATCH http://localhost:9080/api/v1/articles/2

Get a list of articles with pagination support:

curl -i 'http://localhost:9080/api/v1/articles?size=2&page=4&sort=author,DESC'

Deletion of article:

curl -i -X DELETE http://localhost:9080/api/v1/articles/1

spring-boot-2-template's People

Contributors

andrei-punko avatar

Watchers

 avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.