Example of a web service with OpenAPI description implemented using Spring Boot.
This project demonstrates the following features:
- a multimodule Maven project
- parent project chat-service-parent and multiple modules:
- module chat-server - executable server
- module chat-client-java-lib - Java client library generated by OpenAPI Generator "java"
- module chat-client-java - executable client using the library
- module chat-server-generated - executable server generated by OpenAPI Generator "spring"
- module aggregation, where a command executed in the parent project gets executed also in all modules
- module inheritance, where the parent project inherits from
org.springframework.boot:spring-boot-starter-parent
and each module inherits from the parent
- parent project chat-service-parent and multiple modules:
- a Spring Boot application (ChatApplication.java)
- a Spring MVC's REST controller (ChatRestController.java)
- application with multiple layers
- facade - a stable API for the outside world
- service layer - internal business logic
- persistence layer is omitted for the sake of simplicity
- OpenAPI description of the app's API (openapi.yaml) generated from annotated Java code in the REST controller and facade classes
- unit tests executed when the command
mvn test
is issued (ChatRestControllerUnitTests.java) - integration tests executed when the command
mvn verify
is issued (ChatIT.java)
Prerequisites: git, Apache Maven and JDK 21+
Download and compile:
git clone https://github.com/martin-kuba/muni-chat-service.git
cd muni-chat-service
mvn install
cd chat-server
mvn spring-boot:run
Then visit the service with your browser: http://localhost:8080/
cd chat-client-java
mvn spring-boot:run
Create a PKCS12 keystore with:
openssl pkcs12 -export -name "mycert" -inkey key.pem -in cert.pem -certfile chain.pem -out mykeystore.p12
then run with the following options:
java -jar target/chat_service.jar \
--server.port=8443 \
--server.ssl.key-store-type=pkcs12 \
--server.ssl.key-store=mykeystore.p12 \
--server.ssl.key-store-password=password
java -jar target/chat_service.jar \
--server.tomcat.ajp.port=8009 \
--server.tomcat.ajp.enabled=true \
--server.tomcat.ajp.secret=5ecr3t