Check out the full series of Questions Management tutorial here.
Managing and monitoring services in a Microservices system is very important to ensure that our application can operate smoothly. To do this, we first need a place that can be used to register information about services and manage them. For services in the Questions Management application, I will use Spring Cloud Netflix with Eureka Server to do this. In this tutorial, I will go through some important steps in the process of creating support-discovery-server Spring Boot project for this purpose.
In the New Spring Starter Project window, after filling in the information for our project, the Location section should point to the questions-management project folder:
As you can see in the questions-management project folder, I have added a support folder inside this folder to hold all the projects involved in supporting the management and monitoring of services in our Questions Management application.
In the dependencies section for the support-discovery-server project, we only need one dependency, the Spring Cloud Netflix Eureka Server, as follows:
You can read more about the Eureka Server here to understand more.
Result:
Next, I will revise this project so that it uses the parent project of the questions-management project.
First, let’s look at the contents of the pom.xml file in the project we just created:
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 59 60 61 62 63 64 65 66 |
<?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> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.1.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <groupId>com.huongdanjava.qm</groupId> <artifactId>support-discovery-server</artifactId> <version>0.0.1-SNAPSHOT</version> <name>support-discovery-server</name> <description>Support Discovery Server for Questions Management</description> <properties> <java.version>1.8</java.version> <spring-cloud.version>Greenwich.RC1</spring-cloud.version> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> </repository> </repositories> </project> |
I’ll move the <dependencyManagement> and the <spring-cloud.version> section to the questions-management project pom.xml file for future Spring Cloud projects, then delete the <parent>, the <properties>, the <repositories> section for declarations using the questions-management parent project 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 34 35 36 37 38 39 40 |
<?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> <artifactId>support-discovery-server</artifactId> <name>support-discovery-server</name> <description>Support Discovery Server for Questions Management</description> <parent> <groupId>com.huongdanjava.qm</groupId> <artifactId>questions-management</artifactId> <version>0.0.1-SNAPSHOT</version> <relativePath>../../pom.xml</relativePath> </parent> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-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> |
At this point, you will see an error in the pom.xml file related to not finding the dependency for the Spring Cloud:
This is because I removed the <repositories> section of this pom.xml file.
The reason I removed the <repositories> section was because I wanted to define all the repositories needed for the questions-management project in the settings.xml file in the Apache Maven “<user.home>/.m2/” directory. This is very useful for future deployment of Questions Management application.
If you do not know how to define the settings.xml file, you can refer my settings.xml file, as follows:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
<settings> <profiles> <profile> <id>nexus</id> <activation> <activeByDefault>true</activeByDefault> </activation> <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> </repository> </repositories> </profile> </profiles> </settings> |
Finally, I will declare the support-discovery-server project as a module of the questions-management project 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 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
<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</name> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.1.1.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> <spring-cloud.version>Greenwich.RC1</spring-cloud.version> </properties> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>${spring-cloud.version}</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <modules> <module>core/core-category-service</module> <module>core/core-option-service</module> <module>core/core-question-service</module> <module>composite/composite-question-service</module> <module>composite/composite-option-service</module> <module>api/api-category-service</module> <module>api/api-question-service</module> <module>api/api-option-service</module> <module>support/support-discovery-server</module> </modules> </project> |