栏目分类:
子分类:
返回
名师互学网用户登录
快速导航关闭
当前搜索
当前分类
子分类
实用工具
热门搜索
名师互学网 > IT > 软件开发 > 后端开发 > Java

eureka的搭建(注册中心)

Java 更新时间: 发布时间: IT归档 最新发布 模块sitemap 名妆网 法律咨询 聚返吧 英语巴士网 伯小乐 网商动力

eureka的搭建(注册中心)

1.在父项目中导入SpringCloud版本依赖



    
        org.springframework.cloud
        spring-cloud-dependencies
        Hoxton.SR12
        pom
        import
    

1.1在eureka子项目中导入依赖,我用的是jetty云服务,在性能,资源上更有优势.


org.springframework.cloud
spring-cloud-starter-netflix-eureka-server



    org.springframework.boot
    spring-boot-starter-web

    
    
        
            org.springframework.boot
            spring-boot-starter-tomcat
        
    




    org.springframework.boot
    spring-boot-starter-jetty

2.在eureka子项目的resources目录中新建application.yml配置文件

server:
  port: 7001

eureka:
  client:
    service-url:         
      defaultZone: http://localhost:7001/eureka/
    register-with-eureka: false     # 是否要注册到eureka
    fetch-registry: false          #  自身不去获取服务注册信息

3.编写启动类,在网页上输入localhost:7001就能查看了

@SpringBootApplication
@EnableEurekaServer         //  开启服务注册功能
public class EurekaApplication {
    public static void main(String[] args) {
        SpringApplication.run(EurekaApplication.class);
    }
}

4.补充:哪一个服务如果想注册eureka必须添加依赖


    org.springframework.cloud
    spring-cloud-starter-netflix-eureka-client

4.1然后在application.yml中添加配置

spring:
  application:
    name: hello-provider        #服务名称
eureka:
  client:
    service-url:
      defaultZone: http://localhost:7001/eureka/
    register-with-eureka: true     # 是否要注册到eureka
    fetch-registry: false          #  自身不去获取服务注册信息

4.2在启动类上加上@EnableEurekaClient注解,标识当前应用是eureka的客户端

转载请注明:文章转载自 www.mshxw.com
本文地址:https://www.mshxw.com/it/782524.html
我们一直用心在做
关于我们 文章归档 网站地图 联系我们

版权所有 (c)2021-2022 MSHXW.COM

ICP备案号:晋ICP备2021003244-6号