All Projects → JonasHavers → book-catalog

JonasHavers / book-catalog

Licence: Apache-2.0 license
A book-catalog example application written with the Micronaut framework.

Programming Languages

java
68154 projects - #9 most used programming language
HTML
75241 projects
shell
77523 projects
Dockerfile
14818 projects

Projects that are alternatives of or similar to book-catalog

activity-based-security-framework
Exadel Activity-based Security Framework
Stars: ✭ 17 (+13.33%)
Mutual labels:  jdk11
cxf-spring-boot-starter
Enterprise & production ready SOAP webservices powered by Spring Boot & Apache CXF
Stars: ✭ 129 (+760%)
Mutual labels:  jdk11
wonky
Slack made easy for orgs
Stars: ✭ 27 (+80%)
Mutual labels:  micronautfw
design-patterns-in-java
☕ 📖 使用通俗易懂的案例,类图,及配套学习笔记来详解 Java 的二十三种设计模式 !
Stars: ✭ 35 (+133.33%)
Mutual labels:  jdk11
sms
🏫 🎓 一个未使用框架的学生信息管理系统 : 项目概述全面,代码注释详细,逻辑结构清晰,非常适合作为初学 Java web 的同学的第一个练手项目啦 ~
Stars: ✭ 91 (+506.67%)
Mutual labels:  jdk11
susel
Super charge the module aware service loader in Java 11
Stars: ✭ 21 (+40%)
Mutual labels:  jdk11
java11-examples
java 11 example code
Stars: ✭ 90 (+500%)
Mutual labels:  jdk11
sudokufx
AR Sudoku grabber and solver using JavaCV, JavaFX and Scala
Stars: ✭ 64 (+326.67%)
Mutual labels:  jdk11
http-server
A Java HTTP server in 35MB Docker image
Stars: ✭ 17 (+13.33%)
Mutual labels:  jdk11
corretto-docker
Dockerfiles for Amazon Corretto Official images.
Stars: ✭ 53 (+253.33%)
Mutual labels:  jdk11
manon
🧪 Play with SpringBoot 2, JWT, Querydsl, GraphQL, Docker, ELK, PostgreSQL, MariaDB, Redis, MongoDB, Flyway, Maven, Gradle, TestNG, JUnit5, JaCoCo, GreenMail, CI, Quality Gates, Prometheus, Gatling, etc.
Stars: ✭ 26 (+73.33%)
Mutual labels:  jdk11
java-in-termux
This script will install java (openjdk-11/8) in termux without root! Available for aarch64 or armv8, arm64, armhf, armv7l, arm or arm32 or armv7 or aarch32
Stars: ✭ 10 (-33.33%)
Mutual labels:  jdk11

book-catalog

This is a basic example application written with Micronaut that publishes a catalog of books from a MongoDB database via an HTTP API and a server-side Handlebars view.

The example also includes Lombok integration, Jackson configuration, reactive MongoDB connectivity, ConfigurationProperties and a test environment stub.

Please note that additional security configuration is required to use the project in production.

Requirements

How to run the service?

Start the service by executing the bash-script run.sh.

This will:

  • build the Micronaut application JAR file (using the Gradle wrapper),
  • run a Docker multi-container application in daemon mode (using docker-compose),
    • with a MongoDB container
    • with a Micronaut application container
  • seed the MongoDB database with some books (using docker-compose and mongoimport).

You should be able to access http://localhost:8080/ and http://localhost:8080/api/books within a few seconds after the Docker containers are started.

If you are using Docker machine the host might be different (e.g. 192.168.99.100).

Port 8080 of the Micronaut container is exposed to port 8080 by default. You can change the local port by defining the environment variable APPLICATION_PORT:

APPLICATION_PORT=8888 ./run.sh

You can track the logfiles via docker-compose logs -f.

How to stop the service?

Stop the service by executing the bash-script clean.sh.

This will:

  • remove the "build/" directory (from the Gradle build),
  • stop (or kill after 10sec) the Docker multi-container application (using docker-compose),
  • remove all attached Docker resources,
  • remove the Micronaut application image.

How was the project created?

The project itself, the Java beans and controller skeletons were scaffolded using the Micronaut CLI:

$ mn create-app catalogservice.book-catalog --features mongo-reactive
| Generating Java project...
| Application created at /Volumes/projects/github.com/JonasHavers/book-catalog
$ cd book-catalog/
$ mn
| Starting interactive mode...
| Enter a command name to run. Use TAB for completion:
mn> create-bean catalogservice.application.FindBooksUseCase
| Rendered template Bean.java to destination src/main/java/catalogservice/application/FindBooksUseCase.java
mn> create-bean catalogservice.adapter.mongodb.MongoBooksRepository
| Rendered template Bean.java to destination src/main/java/catalogservice/adapter/mongodb/MongoBooksRepository.java
mn> create-controller catalogservice.adapter.web.BooksApiController
| Rendered template Controller.java to destination src/main/java/catalogservice/adapter/web/BooksApiController.java
| Rendered template ControllerTest.java to destination src/test/java/catalogservice/adapter/web/BooksApiControllerTest.java
mn> create-bean catalogservice.adapter.test.StubBooksRepository
| Rendered template Bean.java to destination src/main/java/catalogservice/adapter/test/StubBooksRepository.java

The Lombok dependency and annotation processor were added to the project in build.gradle right before Micronaut's annotation processors:

compileOnly "org.projectlombok:lombok:1.18.4"             // added
annotationProcessor "org.projectlombok:lombok:1.18.4"     // added
annotationProcessor "io.micronaut:micronaut-inject-java"

The Handlebars dependency was added to the project in build.gradle to support server-side view rendering:

runtime "com.github.jknack:handlebars:4.1.2"

The controller that is responsible for the routing and the view model creation was also scaffolded:

$ mn create-controller catalogservice.adapter.web.BooksViewController
| Rendered template Controller.java to destination src/main/java/catalogservice/adapter/web/BooksViewController.java
| Rendered template ControllerTest.java to destination src/test/java/catalogservice/adapter/web/BooksViewControllerTest.java

Implementation and configuration followed the scaffolding. For further details, please refer to the Git history.

Author

Jonas Havers (@JonasHavers) - https://jonas-havers.de

Note that the project description data, including the texts, logos, images, and/or trademarks, for each open source project belongs to its rightful owner. If you wish to add or remove any projects, please contact us at [email protected].