Spring Cloud entry combat (1) ------ build a registration center Eureka

foreword

Eureka is one of the core modules of Spring Cloud for service registration and discovery. This article mainly introduces how to configure and start an Eureka.

text

Example project path

The first step is to rely on

The dependencies required to start Eureka are configured in Maven's .pom file:

    <dependencies>
        <!-- 1.3.1.RELEASE 对应spring版本为4.3.8 -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-eureka-server</artifactId>
            <version>1.3.1.RELEASE</version>
        </dependency>
    </dependencies>

Each eureka version also corresponds to a different spring version. I chose 1.3.1.RELEASE because the local spring version is 4.3.8.RELEASE.

The second step is to configure

Define a configuration file, either named application.yml or application.properties.

server:
  port: 8762
eureka:
  instance:
    hostname: localhost
  client:
    registerWithEureka: false
    fetchRegistry: false
    serviceUrl:
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

The third step, start

Build the startup class:

package com.silence.spring.cloud.eureka;

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

@SpringBootApplication
@EnableEurekaServer
public class EurekaApplication {

    public static void main(String[] args) throws Exception {
        SpringApplication.run(EurekaApplication.class, args);
    }

}

Spring Cloud relies on Spring Boot, which simplifies the related configuration work.

verify

After startup, type the link address in the browser: http://localhost:8762/ , if the following figure appears, it proves that Eureka has been started successfully.
Eureka

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=325853272&siteId=291194637