Spring Cloud 集成 euraka-server 和 euraka-client

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_35704236/article/details/79642424

euraka-server

1 导入 依赖

ext {
    springCloudVersion = 'Finchley.M2'
}

// 依赖关系
dependencies {

    // Eureka Server
    compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-server')

    // 该依赖用于测试阶段
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

2 配置 yml

server:
  port: 8888

eureka:
    instance:
        hostname: localhost
    client:
        registerWithEureka: false
        fetchRegistry: false
        serviceUrl:
            defaultZone: http://localhost:8888

在启动类上标明 @EnableEurekaServer

@SpringBootApplication
@EnableEurekaServer
public class Application {

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

euraka-client

1 导入 依赖

ext {
    springCloudVersion = 'Finchley.M2'
}

// 依赖关系
dependencies {

    // Eureka Client
    compile('org.springframework.cloud:spring-cloud-starter-netflix-eureka-client')

    // 该依赖用于测试阶段
    testCompile('org.springframework.boot:spring-boot-starter-test')
}

dependencyManagement {
    imports {
        mavenBom "org.springframework.cloud:spring-cloud-dependencies:${springCloudVersion}"
    }
}

2 配置 yml

spring:
    application:
        name: micro-weather-eureka-client
        # euraka 客户端实例
eureka:
    client:
        serviceUrl:
            defaultZone: http://localhost:8888/eureka/
            # euraka server路径

在启动类上标明 @EnableDiscoveryClient

@SpringBootApplication
@EnableDiscoveryClient
public class Application {

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

猜你喜欢

转载自blog.csdn.net/qq_35704236/article/details/79642424