温馨提示×

温馨提示×

您好,登录后才能下订单哦!

密码登录×
登录注册×
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》

使用SpringCloud怎么实现Eureka服务发现

发布时间:2021-05-27 18:12:13 来源:亿速云 阅读:147 作者:Leah 栏目:编程语言

今天就跟大家聊聊有关使用SpringCloud怎么实现Eureka服务发现,可能很多人都不太了解,为了让大家更加了解,小编给大家总结了以下内容,希望大家根据这篇文章可以有所收获。

1、Eureka服务端集群开发

1、先创建一个父工程

若是不是普通demo,还有别的配置时,需要注意若是服务开不起来可能就是父类依赖中可能会需要<dependencyManagement>这个标签。

2、再创建两个子工程

1、导入依赖

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

2、配置文件application.yml

#内置的tomcat服务启动监听端口号
server:
 port: 6002

#EurekaServer配置
eureka:
 instance:
  hostname: eureka6002  #EurekaServer的名字
 client:
  register-with-eureka: false #此EurekaServer不在注册到其他的注册中心
  fetch-registry: false    #不在从其他中心中心拉取服务器信息
  service-url:
   defaultZone: http://eureka6001.com:6001/eureka #注册中心访问地址---------------------------------------
#内置的tomcat服务启动监听端口号
server:
 port: 6001
#EurekaServer配置
eureka:
 instance:
  hostname: eureka6001
 client:
  register-with-eureka: false #此EurekaServer不在注册到其他的注册中心
  fetch-registry: false    #不在从其他中心中心拉取服务器信息
  service-url:
   defaultZone: http://eureka6002.com:6002/eureka #注册中心访问地址

3、主启动类

@SpringBootApplication  //标记这是主启动类
@EnableEurekaServer    //标记这是EurekaServer
public class AppStart2 {
  public static void main(String[] args) {
    SpringApplication.run(AppStart2.class, args);
  }
}

2、微服务配置

1、导入依赖,上面的依赖

2、配置application.yml中添加

eureka:
 client:
  register-with-eureka: true #允许注册到EurekaServer
  fetch-registry: true    #从其他中心中心拉取服务器信息
  service-url:
   defaultZone: http://eureka6002.com:6002/eureka,http://eureka6001.com:6001/eureka #注册中心访问地

3、主启动类

@SpringBootApplication
@EnableEurekaClient  //标记这是一个Euerka客户端,必须要写
public class ProductProvider_8001 {
  public static void main(String[] args) {
    SpringApplication.run(ProductProvider_8001.class,args);
  }
}

3、启动项目

访问http://localhost:6001/ 和 http://localhost:6002/

使用SpringCloud怎么实现Eureka服务发现

看完上述内容,你们对使用SpringCloud怎么实现Eureka服务发现有进一步的了解吗?如果还想了解更多知识或者相关内容,请关注亿速云行业资讯频道,感谢大家的支持。

向AI问一下细节

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

AI