In this series of previous article, we practiced how to build a registration and discovery service. Now, we are going to practice registering a business service.
In this experiment, we use an example built on Spring Boot to serve as a developed business segment. For example construction, please refer to Spring Boot 构建Rest服务实验手册(一)
To use the Spring Boot application as a registerable service of Spring Cloud, you only need to simply change the following three places in the project:
Add dependency library
In the project’s pom.xml file:
- Change the version number of the project’s parent element spring-boot-starter-parent to: 2.0.5.RELEASE, the modified version is as follows:
1 | <parent> |
- Add the following dependency libraries and dependency management items:
1 | <dependency> |
1 | <dependencyManagement> |
Modify the startup class
Add @EnableEurekaClient annotation to the startup class of Spring Boot application, the code is as follows:
1 |
|
Delete test class
Delete the test class in the test/java directory.
Modify the application.yaml configuration file
Add the following content in the project configuration file: application.yaml:
1 | spring: |
Start the program and verify
Start the application and visit the registration server to see if the current application has been registered:
1 | http://localhost:8761 |
Next
In next step, we will practice a Gateway in Spring Cloud.