Check out the full series of Questions Management tutorial here.
API Services are the services that expose the API to external systems that can be used. They will call the other services in the Core Service or Composite Service depending on the needs of the user. In this tutorial, I show you how to create the Spring Boot project for first API Service, the API Category Service.
The steps to create a Spring Boot project, I already guided to you all. Here, I only mention some important points in the process of creating projects for the API Service Category only.
In the New Spring Starter Project window, after filling in the information about our project, in the Location section, you point to the project questions-management directory:
As you can see in the questions-management project folder, I have added an api folder inside this directory to contain all of the API Services related projects.
For the dependencies to use for the api-category-service project because API Service will not have any operations on the database, we will only use the following dependencies:
- Reactive Web: See also Introduce about Spring WebFlux
- Lombok: more about Introduction about Project Lombok
- DevTools: See also Introduction about DevTools in Spring Boot
Result:
Next, I’ll revise this project a little bit so that it uses the parent project of the project questions-management.
In this project’s pom.xml file, I will delete the current <parent> and <properties> to declare using the parent project of the project questions-management:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
<?xml version="1.0" encoding="UTF-8"?> <project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.huongdanjava</groupId> <artifactId>api-category-service</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>api-category-service</name> <description>API Category Service for Questions Management</description> <parent> <groupId>com.huongdanjava</groupId> <artifactId>questions-management</artifactId> <version>0.0.1-SNAPSHOT</version> </parent> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-webflux</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-devtools</artifactId> <scope>runtime</scope> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <optional>true</optional> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>io.projectreactor</groupId> <artifactId>reactor-test</artifactId> <scope>test</scope> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> </project> |
Then declare the project api-category-service as a module of the project questions-management as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <groupId>com.huongdanjava</groupId> <artifactId>questions-management</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>pom</packaging> <name>Questions Management System</name> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.0.3.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> </properties> <modules> <module>core/core-category-service</module> <module>core/core-question-service</module> <module>core/core-option-service</module> <module>composite/composite-question-service</module> <module>api/api-category-service</module> </modules> </project> |