码迷,mamicode.com
首页 > 编程语言 > 详细

spring cloud Eureka服务注册

时间:2020-05-05 20:12:04      阅读:59      评论:0      收藏:0      [点我收藏+]

标签:程序   public   yml   默认   with   情况   创建   server   start   

yls
2020/5/5

创建注册管理中心

1.添加依赖

<!--服务注册中心 start-->
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-server</artifactId>
        </dependency>
        <!--服务注册中心 end-->

2.在启动程序添加注解@EnableEurekaServer

@EnableEurekaServer
@SpringBootApplication
public class ItokenEurekaApplication {
    public static void main(String[] args) {
        SpringApplication.run(ItokenEurekaApplication.class, args);
    }
}

3.创建配置文件application.yml

spring:
  application:
    name: itoken-eureka
server:
  port: 8761

eureka:
  instance:
    hostname: localhost
  client:
    #表示是否将自己注册到eureka,因为要构建集群,需要将自己注册到集群,所以需要开启
    registerWithEureka: true
    #表示是否从eureka获取到注册信息,这里为集群,所以应该开启
    fetchRegistry: true
    serviceUrl:
      #表示从默认分区中访问eureka server,多个eureka用过逗号隔开
      defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/,http://${eureka.instance.hostname}:8861/eureka/

4.运行项目后,打开网址http://localhost:8761成功即可

微服务注册到服务注册中心

1.添加依赖

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

2.在启动类上添加注解@EnableEurekaClient

3.添加配置文件application.yml

spring:
  application:
    name: itoken-config
server:
  port: 8888
eureka:
    client:
      serviceUrl:
        defaultZone: http://localhost:8761/eureka/

4.在注册中心启动的情况下,启动该服务,然后在注册中心可以看到该实例

spring cloud Eureka服务注册

标签:程序   public   yml   默认   with   情况   创建   server   start   

原文地址:https://www.cnblogs.com/yloved/p/12832063.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!