This is a demo application for online bookstore, providing browsing, purchasing book via end user's browser etc.
It is built on top of Spring Boot framework, since Spring Boot is a great framework for building microservices quickly and easily, and also the Spring Community is very active and has a lot of great resources and outstanding solutions for common problems.
To simplify demo, here putting book service and cart service into one project.
- Java 21
- Spring Boot 3.3.4
- Spring Data JPA
- Spring Event
- Hibernate
- H2 Database
- Lombok
- JUnit5
- Mockito
- Mapstruct
- Swagger UI
- Gradle 8+
- Flyway
- RFC-9457
- Version Catalog
- Checkstyle
- Spotless
- Testcontainers
follow RFC-9457 specification to response with standard error output, it is clean and easier to align with Frontend or other integration point.
- The api specification is generated by Swagger UI. You can access it via API Specification
- API Versioning on URL path is supported.
- export above Api Specification into JSON file and import into Postman or other similar tools
- checkout each API and try it out
- you can also try it out via curl or other tools
- API explanation as below:
/books/v1/
: create a book with title and price etc./books/v1/{id}
: get a book by id, if not found then return 404./books/v1/{index}/{size}
: get a page of books with index and size./carts/v1/book/
: add a book into current user's cart, will return cart id./carts/v1/{id}/book/
: incr or decr a book's purchased amount from current user's cart by cart id./carts/v1/books/
: get all books from current user's cart./checkouts/v1/summary
: get a summary (total price) of current user's cart.
- Clone this repository
- Run the following command in the root directory of the project
if you have installed Gradle in your environment, then just run:
gradle clean bootRun
otherwise, then run
./gradlew clean bootRun
- Clone this repository
- Run the following command in the root directory of the project
gradle clean test
otherwise, then run
./gradlew clean test
- Test Report will be generated under
build/reports/tests/test/index.html
- Clone this repository
- Run the following command in the root directory of the project
gradle clean jacocoTestReport
3.Coverage report will be generated under
build/reports/jacoco/test/index.html
4.Report example as following
http://localhost:8080/actuator http://localhost:8080/actuator/refresh http://localhost:8080/actuator/health
https://github.com/redis/lettuce/wiki/Connection-Pooling
- Global Exception Handler
- Entity Convertor
- Distributed Lock
- Custom Metrics
- Auto reload yaml file and refresh properties bean
- Checkstyle (https://checkstyle.sourceforge.io/google_style.html)
- Spotless https://github.com/diffplug/spotless/tree/main/plugin-gradle#requirements
- API Doc https://springdoc.org/
- Testcontainers https://testcontainers.com/guides/testing-spring-boot-rest-api-using-testcontainers/
- Native https://docs.spring.io/spring-boot/docs/3.2.3/reference/html/native-image.html
Raw executable jar: 3.383 seconds
Unpack executable jar: 2.815 seconds (+16%)
Unpack + CDS executable jar: 1.966 seconds (+30%)
Unpack + CDS + AOT executable jar: 1.54 seconds (+21%)
GraalVM jar: 0.365 seconds (+90%)
from ben-logs files, showing that native image outperform jvm on requests/sec.
- Code generation does not support org.springframework.cloud.context.scope.refresh.RefreshScope
- in AOT, Unable to find 'record-request-start-time' in UndertowOptions