Hello everyone, I am Chu Chen, in this chapter we will learn the use of SpringCloud Client. Questions and comments can be sent to [email protected]


One: Create a SpringCloud Client

The steps for creating Spring Cloud Eureka are basically the same as those for creating Spring Cloud Eureka. The difference is that the service is selected according to the following figure



Select Eureka Discovery and import the JAR package

Two: Start eureka created in the previous section, this is essential, in the future when starting other services eureka is enabled by default!

Three: Configure the client

1: add @enableDiscoveryClient to the startup class

Indicates that the service is a client



2: Set the Eureka address

Add the following configuration to tell client our eureka address

Note: Here we change the application to a YML file

3: Start the project

After we started, we found that the project stopped running on its own. Here we open the POM file and add the following dependencies

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>Copy the code

4: The system starts again



5: Open the Eureka page

http://localhost:8761/Copy the code



We found that the client has been registered in Eureka

Four: high availability

High availability means that I can register multiple ports for the same service, so that if one of the services fails, the project will not be affected

1: Changes the default port number of the client





Example Change the port number to 8081

2: Adds the client service



Choose copy





Example Change the port number to 8082

3: Restarts the two clients

4: Open the Eureka startup page

http://localhost:8761/Copy the code



It can be found that two clients are registered successfully, and the ports are 8081 and 8082 respectively

Five: the ending

Thank you for your support. The app center will be updated in the future. Thank you.

For springBoot do not know friends can see my springBoot series tutorial