Eureka-使用教程

Eureka-使用教程,第1张

一 Eureka-server 注册中心

1.pom配置


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

2.application.yml

server:
  port: 10086
spring:
  application:
    name: eurekaserver  #eureka的名称
eureka:
  client:
    service-url: #eureka的通信地址
      defaultZone: http://127.0.0.1:10086/eureka

3.SpringbootApplication启动项

@EnableEurekaServer

二、eureka-client 客户端配置
1.设置pom


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

2. 设置application.yml

#eureka-cli
eureka:
  client:
    service-url: #eureka的通信地址
      defaultZone: http://127.0.0.1:10086/eureka
spring:
  application:
    name: orderservice  #eureka的user服务名称

 如果本地需要多个配置

右键复制一个新的running 进行修改,名字修改和截图内红框参数需要添加

运行后,可以在

http://127.0.0.1:10086/     注册中心看到运行状况

服务拉取

1.修改代码url访问路径,用服务名替代ip,端口:

Spring url = "http://USERSERVER/user/"  + order.getUser();

2.在启动项Application中的RestTemplate添加负载均衡注解。

@Bean

@LoadBalanced

public RestTemplate restTemplate(){

        return new RestTemplate();

}

 Eureka常用配置情况有异常或者有问题的可以给我留言。互相学习~

欢迎分享,转载请注明来源:内存溢出

原文地址: https://outofmemory.cn/langs/868910.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2022-05-13
下一篇 2022-05-13

发表评论

登录后才能评论

评论列表(0条)

保存