Use Eureka to build a registry

Use Eureka to build a registry

  1. Introduction to SpringCloud and Maven
    Maven: Two core functions of Maven: dependency management (jar package management); building projects (project packaging).
    Products of the same type: ant and gradle. Ant has basically died out. Gradle and maven coexist, the number of gradle users has been increasing, and the domestic environment is still dominated by maven.
    Core products: SpringBoot and SpringCloud. SpringBoot is a single application development framework. SpringCloud is a microservice framework for managing multiple SpringBoot applications.
  2. Use spring initializr to create spring cloud project

The difference between Spring Initializr and Maven: Use "spring initializr" to create a project, you can intuitively manually check the dependencies, after the project is successfully created, the pom.xml will have its own dependencies (as shown below);
use "Maven" to create a project, you need to Add dependencies to the pom.xml folder (suitable for use in poor network environments).

  1. Transform the project into a Maven parent-child structure

Insert picture description here
Give it to the git management page, start the SpringBoot project, and find that there is an error.
Insert picture description here
We are now a single SpringBoot project, we want to transform our Maven into a parent-child project.

  1. New module
    Insert picture description here
  2. Create the eureka module.
    Insert picture description here
  3. Move the eureka module of the parent pom to the child module.Insert picture description here
  4. Finally, start it and you can successfully use Eureka to build a registry.Insert picture description here

Maven parent-child module structure: The parent framework only needs one pom.xml, and the sub-module is a normal maven project. Then the submodule is a springboot project

Note:
If com.sun.jersey.api.client.ClientHandlerException: java.net.ConnectException: Connection refused: connect is reported.

  • This is because eureka will register itself as a client in the default configuration. At startup, it will register itself as a client at the same time. And in the process of starting. Even if the server itself is also the client. The server hasn't been started yet, and the client will definitely report an error if it finds it!

spring.application.name=eureka
server.port=8761 #Whether to
register yourself to Eureka Server, the default is true
eureka.client.register-with-eureka=false #Whether
to obtain registration information from Eureka Server, the default is true
eureka .client.fetch-registry=false

The solution is to add this code in application.properties.
Insert picture description here
And add @EnableEurekaServer annotation to the startup class
Insert picture description here

There is one thing to pay attention to. If a plurality of sub-modules, it needs to be registered with the service registry, Step 2: Add Configuration, point to registry address
Insert picture description here
eureka.client.service-url.defaultZone = http: // localhost : 8761 / eureka /
but also in Add the annotation
@EnableEurekaClient to the startup classInsert picture description here

Guess you like

Origin blog.csdn.net/weixin_45647118/article/details/114328644