Spring Cloud学习笔记:Eureka服务注册与消费

基础配置

开发工具 :IDEA
MAVEN :3.6
JDK : 1.8
Spring boot :1.5.9.RELEASE
Spring cloud : Edgware.RELEASE

pox配置信息

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

服务端:

服务端启动文件添加注解:

@EnableEurekaServer

注意:导入包为:

import org.springframework.cloud.netflix.eureka.server.EnableEurekaServer;

application.properties配置:

spring.application.name=cloud-eureka //应用程序名

server.port=8761//端口号,服务端使用8761

eureka.instance.hostname=localhost //设置当前实例的主机名称

eureka.client.register-with-eureka=false//启动服务注册,自己就是server端,避免向自己注册
eureka.client.fetch-registry=false//检查索引,避免eureka查找服务列表

eureka.client.service-url.defaultZone=http://${eureka.instance.hostname}:${server.port}/eureka/

//自我保护机制,Eureka Server启动时会创建定时任务
//默认60s一次,将当前清单中超时(90s)没有续约的服务剔除。
eureka.server.enable-self-preservation=false 
eureka.server.eviction-interval-timer-in-ms=5000

客户端:

客户端启动文件添加注解:

@EnableEurekaClient(@EnableDiscoveryClient)两个都可以

注意:导入包为:

import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
//import org.springframework.cloud.client.discovery.EnableDiscoveryClient;

application.properties配置:

application.properties配置:
spring.application.name=cloud-client1

server.port=8082

eureka.client.service-url.defaultZone=http://localhost:8761/eureka/

访问地址:localhost:8761,能进入并且在Application表中cloud_client1的客服端。

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值