tufangorel / spring-boot-data-jpa-programmatic-transaction-management

spring-boot-data-jpa-programmatic-transaction-management

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

spring-boot-data-jpa-programmatic-transaction-management

Purpose : Use programmatic transaction management instead of @Transactional annotation.
Reason : Get rid of annotation processing cost.

Local run steps

1- Call customer/saveprogrammatic rest end-point to save customer record.
2- Call customer/list rest end-point to list all customer records.
3- Before starting the application run mvn clean install to generate mapstruct mapper class.
4- If generated mapstruct mapper class is not recognized by IntelliJ IDE then reload all maven projects.
5- Start Spring Boot REST API by running main method containing class CustomerInfoApplication.java in your IDE.
6- Alternatively you can start your Docker container by following the commands below.
NOT : Execute maven command from where the pom.xml is located in the project directory to create Spring Boot executable jar.

 
$ mvn clean install -U -X 
$ mvn spring-boot:run

swagger_ui can be accessed via https secure port 8443 from localhost :
https://localhost:8443/customer-info/swagger-ui/index.html

https_swagger_ui

Database ER diagram :
https_swagger_ui

Tech Stack

Java 11
H2 Database Engine
spring boot
spring boot starter data jpa
spring boot starter web
spring boot starter test
spring boot starter aop
spring boot starter actuator
spring security web
springdoc openapi ui
springfox swagger ui
querydsl-jpa
querydsl-apt
hibernate
logback
maven
mapstruct
mapstruct-processor
hikari connection pool
mockito-core
mockito-junit-jupiter
mockito-inline
Docker

Docker build run steps

NOT : Execute docker commands from where the DockerFile is located.
NOT : Tested on Windows 10 with Docker Desktop Engine Version : 20.10.11

$ docker system prune -a --volumes 
$ docker build . --tag demo
$ docker images
REPOSITORY TAG IMAGE ID CREATED SIZE
demo latest 9d4a0ec3294e 6 minutes ago 288MB
$ docker run -p 8443:8443 -e "SPRING_PROFILES_ACTIVE=dev" demo:latest

API OPERATIONS

Save a new customer to database

Method : HTTP.POST
URL : https://localhost:8443/customer-info/customer/saveprogrammatic
HTTP Request Body :

{
    "name": "name1",
    "age": 1,
    "shippingAddress": {
        "address": {
            "streetName": "software",
            "city": "ankara",
            "country": "TR"
        }
    }
}

Curl Request :

curl --location --request POST 'https://localhost:8443/customer-info/customer/saveprogrammatic' \
--header 'Content-Type: application/json' \
--data-raw '{
    "name": "name1",
    "age": 1,
    "shippingAddress": {
        "address": {
            "streetName": "software",
            "city": "ankara",
            "country": "TR"
        }
    }
}'

Response :

HTTP response code 200

{
    "id": 1,
    "name": "name1",
    "age": 1,
    "shippingAddress": {
        "id": 1,
        "address": {
            "id": 1,
            "streetName": "software",
            "city": "ankara",
            "country": "TR"
        }
    }
}

HTTP Response Headers :

request-id: 68182bbf-996d-4732-a6ff-2c49a90012d1
correlation-id: 68182bbf-996d-4732-a6ff-2c49a90012d1
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers

List all customers saved to database

Method : HTTP.GET
URL : https://localhost:8443/customer-info/customer/list
Request Body :

{}

Curl Request :

curl --location --request GET 'https://localhost:8443/customer-info/customer/list' \
--header 'Content-Type: application/json' \
--header 'Cookie: JSESSIONID=5E6B21C9533643F4A7EE462DCBB3B312' \
--data-raw '{}'

Response :

HTTP response code 200

[
    {
        "id": 1,
        "name": "name1",
        "age": 1,
        "shippingAddress": {
            "id": 1,
            "address": {
                "id": 1,
                "streetName": "software",
                "city": "ankara",
                "country": "TR"
            }
        }
    }
]

HTTP Response Headers :
request-id: 411b4b33-6af5-4f78-b185-4171e779222d
correlation-id: 411b4b33-6af5-4f78-b185-4171e779222d
Vary: Origin
Vary: Access-Control-Request-Method
Vary: Access-Control-Request-Headers

About

spring-boot-data-jpa-programmatic-transaction-management


Languages

Language:Java 99.6%Language:Dockerfile 0.4%