spring-cloud-Eureka基础配置

世界上并没有完美的程序,但是我们并不因此而沮丧,因为写程序就是一个不断追求完美的过程。

EurekaServer
依赖:

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR8</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

注解:

@SpringBootApplication
@EnableEurekaServer
@RefreshScope
public class HserverApplication

配置:

spring:
  application:
    name: hserver
eureka:
  instance:
    hostname: localhost
    instance-id: hserver
  client:
    fetch-registry: false
    register-with-eureka: false
    service-url:
      defaultZone: http://localhost:8999/eureka
  server:
    wait-time-in-ms-when-sync-empty: 0
    enable-self-preservation: true
    peer-eureka-nodes-update-interval-ms: 1000000

EurekaClient
依赖:

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

        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>

        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
    </dependencies>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>Hoxton.SR8</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

注解:

@SpringBootApplication
@EnableEurekaClient
@RefreshScope
public class HapplicationinterfaceApplication

配置:

spring:
  application:
    name: happlicationinterface

eureka:
  client:
    service-url:
      defaultZone: http://localhost:8999/eureka

然后先启动Server后启动Client,显示界面如下:
http://localhost:8999/
在这里插入图片描述
在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/a13662080711/article/details/108440499