Hello everyone, I am Chu Chen, in this chapter we will learn the use of SpringCloud Eureka. Questions and comments can be sent to [email protected]
A: SpringCloud Eureka
- SpringCloud Eureka is a secondary package based on Netflix Eureka
- It is divided into two parts: 1. 2. Service registration
2. Set up the Eureka Server
1: Create the infrastructure
The basic steps of creating a SpringCloud project are basically the same as SpringBoot.
Create a reference to the following group of images, points to note with red blocks
The directory is as follows:
Don’t forget to refresh the POM.xml file to download the required JAR packages.
Steps: Right-click the POM file and choose Maven→Reimport
2: Adds the configuration
Annotate the startup class with @enableeurekaserver
This annotation indicates that the project is the Eureka registry
3: Start the project
After starting the project, access localhost:8080 and you can see the following interface, indicating that the project is successfully created
4: Handle project errors
At this point, careful friends may notice that although we have successfully started, but the console continues to report errors, what is the reason?
This is because Eureka itself is not only a registry end, but also a server end. In this case, it will search for the registry end in a polling way and register itself. In order to prevent it from reporting errors, we will add the configuration to point the registration address to itself
Modify the configuration file suffix. We use the.yml configuration file to add the following configuration
eureka:
client:
service-url:
defaultZone: http://localhost:8080/eureka/ Copy the code
Again we found that he still reported an error
Eureka tried to register with localhost:8080/eureka/ before the project was started. No error will be reported after the project is started.
Access localhost:8080 again
We found that the service was registered successfully, but the service name was not displayed. So we add the following configuration:
eureka:
client:
service-url:
defaultZone: http://localhost:8080/eureka/
spring:
application:
name: eureka Copy the code
Restart access
The eureka service itself functions as a registry and should not appear under Instances currently Registered with Eureka. Therefore, we add the following configuration:
eureka:
client:
service-url:
defaultZone: http://localhost:8080/eureka/
register-with-eureka: false
spring:
application:
name: eurekaCopy the code
Start access again:
Ok, success!
5: Change the IP address
Change the IP address to Eureka’s default IP address 8761
-Dserver.port=8761Copy the code
Again, visit http://localhost:8761/
3: at the end
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