首页 > 编程语言 > 详细

spring cloud:eureka

时间:2019-05-19 21:05:13      阅读:109      评论:0      收藏:0      [点我收藏+]

Eureka-server

1.file-->new--> spring starter project  : eureka-server

2.添加依赖

  <!-- eureka-server -->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
            <version>2.1.1.RELEASE</version>
        </dependency>
        <!-- eureka-server -->

3.修改port:新建application.yml:

server:
  port: 8761

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

 

4. EurekaServerApplication添加注解@EnableEurekaServer

package com.smile.eurekaserver;

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

@SpringBootApplication
@EnableEurekaServer
public class EurekaServerApplication {

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

}

5访问:http://localhost:8761/ 

技术分享图片

 Eureka-client

1.file-->new--> spring starter project  : eureka-client

2.添加依赖

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

 

3.修改port:新建application.yml:

server:
  port: 8001

eureka:
  client:
#    registerWithEureka: false
#    fetchRegistry: false
    serviceUrl:
      defaultZone: http://localhost:8761/eureka/

spring:
  application:
    name: eureka-client

 

 

4. EurekaClientApplication添加注解@@EnableEurekaClient

package com.smile;

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

@SpringBootApplication
@EnableEurekaClient
public class EurekaClientApplication {

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

}

 

5启动项目,访问:http://localhost:8761/  这里已经多了一个instance

技术分享图片

 

spring cloud:eureka

原文:https://www.cnblogs.com/alittlesmile/p/10883112.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!