小D课堂

笔记


5、服务注册和发现Eureka Server搭建实战
    简介:使用IDEA搭建Eureka服务中心Server端并启动,项目基本骨架介绍
    
    官方文档:http://cloud.spring.io/spring-cloud-netflix/single/spring-cloud-netflix.html#spring-cloud-eureka-server

    第一步:创建项目
    第二步: 添加注解 @EnableEurekaServer
    第三步:增加配置application.yml
            server:
              port: 8761

            eureka:
              instance:
                hostname: localhost
              client:
              #声明自己是个服务端
                registerWithEureka: false
                fetchRegistry: false
                serviceUrl:
                  defaultZone: http://${eureka.instance.hostname}:${server.port}/eureka/

    第四步:访问注册中心页面

    maven地址: https://www.cnblogs.com/sword-successful/p/6408281.html

开始



https://start.spring.io/







因为我们现在要做配置注册中心。所以这里选择Eureka Server这一个选项就可以了。


确认好路径和项目名称,直接finish

然后会自动下载很多的jar包根据网络情况而定
可以把maven的仓库地址换成阿里云的
右下角选择自动导入相关的依赖


pom.xml和学spring boot的时候没有什么区别,唯一区别可能就是所了个eureka的依赖

就是一个空的项目


https://cloud.spring.io/spring-cloud-netflix/reference/html/#spring-cloud-eureka-server

启动类里面加注解


Standalone Mode:单例模式。这里用的是application.yml的配置文件

我们创建的代码代码是application.properties格式的

所以我们要对配置文件的格式修改。改成yml格式

把后缀改成yml格式的


把官方文档的案例代码复制过去。

server:
  port: 8761

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

每个缩进都是两个空格。key和值之间是一个空格



启动程序




当前没有实例注册到应用中心







 

原文地址:https://www.cnblogs.com/wangjunwei/p/11440946.html