Eureka-demo polymerization project. SpringBoot 2.2.4.RELEASE, Spring Cloud hoxton.sr1

  

Create a project

  

We create an aggregation project to illustrate Eureka, starting with creating a POM parent project.

  

Add the dependent

pom.xml

4.0.0

<! <groupId>com.example</groupId> <! --> <artifactId> Eureka-demo </artifactId> <! -- Project Version Name SNAPSHOT version, official version RELEASE --> <version>1.0-SNAPSHOT</version> <! -- Inherits spring-boot-starter-parent dependency --> <! -- Use inheritance to achieve reuse, GroupId >org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> The < version > 2.2.4. RELEASE < / version > < / parent > <! --> <properties> <! -- Spring Cloud hoxton.sr1 dependencies --> < spring-cloud-version > hoxton.sr1 </ spring-cloud-version > </properties> <! <dependencyManagement> <dependencies> <! - spring cloud depend on - > < the 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>Copy the code

  

Registry Eureka-Server

  

The project to create the Eureka-Server registry under the previous parent project.

  

Create a project

  

  

Add the dependent

  

pom.xml

4.0.0

< the groupId > com. Example < / groupId > < artifactId > eureka - server < / artifactId > < version > 1.0 - the SNAPSHOT < / version > <! Example </groupId> <artifactId>eureka-demo</artifactId> < version > 1.0 - the SNAPSHOT < / version > < / parent > <! --> <dependencies> <! - netflix eureka server rely on - > < the 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-web</artifactId> </dependency> <! --> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> <exclusions> <exclusion> <groupId>org.junit.vintage</groupId> <artifactId>junit-vintage-engine</artifactId> </exclusion> </exclusions> </dependency> </dependencies>Copy the code

  

The configuration file

  

application.yml

Server: port: 8761 #

Spring: Application: name: eureka-server #

Configure the Eureka Server registry

Client: register-with-eureka: instance: hostname: localhost False # Whether to fetch service registration information from the registry, default is true service-url: DefaultZone: http:// eureka.instance.hostname:{eureka.instance.hostname}:eureka.instance.hostname:{server.port}/eureka/

At this point if directly start the project will be an error, error message: com. Sun. Jersey. API. Client. ClientHandlerException: java.net.ConnectException: Connection refused: connect

This is because Eureka has enabled registering itself in the registry and obtaining service registration information from the registry by default, which is turned off if the application is a single node in the role of the registry.

  

Start the class

  

EurekaServerApplication.java

package com.example;

import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

@enableEurekaserver Public class EurekaServerApplication {

public static void main(String[] args) {
    SpringApplication.run(EurekaServerApplication.class, args);
}
Copy the code

}

access

  

Visit: http://localhost:8761/

Today to say the Eureka entry case temporarily said so much, to learn more about technology dry goods, pay attention to the public number [letbyte send 123 can understand, we learn together acro], I am Miles, an interesting soul! See you next time!