Springboot2.0.X升级到SpringCloud详解及问题

1 篇文章 0 订阅
0 篇文章 0 订阅

1.配置一个Eureka集群注册中心的配置如下

spring:
  profiles:
    active: first
  application:
      name: xxx.system

---
spring:
  profiles: first
server:
  port: 5060
eureka:
  instance:
    hostname: http://localhost:5060
    preferIpAddress: true
  client:
    register-with-eureka: true
    fetch-registry: true
    serviceUrl:
      defaultZone: http://localhost:5061/eureka/,http://localhost:5062/eureka/
  server:
    #实例,此时调用会失败,对于这个问题需要服务消费者端有一些容错机制,如重试、断路器等;
    enableSelfPreservation: false
    #扫描失效服务的间隔时间(单位是毫秒,摩恩是60*1000),即60s
    eviction-interval-timer-in-ms: 10000

---    
spring:
  profiles: second
server:
  port: 5061
eureka:
  instance:
    hostname: http://localhost:5060
    preferIpAddress: true
  client:
    register-with-eureka: true
    fetch-registry: true
    serviceUrl:
      defaultZone: http://localhost:5060/eureka/,http://localhost:5062/eureka/
  server:
    #实例,此时调用会失败,对于这个问题需要服务消费者端有一些容错机制,如重试、断路器等;
    enableSelfPreservation: false
    #扫描失效服务的间隔时间(单位是毫秒,摩恩是60*1000),即60s
    eviction-interval-timer-in-ms: 10000
---
spring:
  profiles: three
server:
  port: 5062
eureka:
  instance:
    hostname: http://localhost:5060
    preferIpAddress: true
  client:
    register-with-eureka: true
    fetch-registry: true
    serviceUrl:
      defaultZone: http://localhost:5060/eureka/,http://localhost:5061/eureka/
  server:
    #实例,此时调用会失败,对于这个问题需要服务消费者端有一些容错机制,如重试、断路器等;
    enableSelfPreservation: false
    #扫描失效服务的间隔时间(单位是毫秒,摩恩是60*1000),即60s
    eviction-interval-timer-in-ms: 10000

分别启动:

  1. java -java  xxx.jar -- --spring.profiles.active=first
  2. java -java  xxx.jar -- --spring.profiles.active=two
  3. java -java  xxx.jar -- --spring.profiles.active=three

2.先需要在pom.xml引入(以下是springboot2.0.X对应需要的jar包)

<dependencyManagement>
    <dependencies>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-dependencies</artifactId>
            <version>Finchley.SR1</version>
            <type>pom</type>
            <scope>import</scope>
        </dependency>
    </dependencies>
</dependencyManagement>

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

<dependency>
 <groupId>org.springframework.cloud</groupId>
 <artifactId>spring-cloud-starter-openfeign</artifactId>
</dependency>

3.提供者配置文件

#eureka配置
eureka:
  client:
    service-url:
      defaultZone: http://localhost:5060/eureka/,http://localhost:5061/eureka/,http://localhost:5062/eureka/
  instance:
    hostname: dev
    prefer-ip-address: true
    instance-id: http:localhost:9091  #当前机器的IP最好是IP
feign:
  hystrix:
    enabled: true

# 关于springcloud-hystrix机制 http://www.jianshu.com/p/b8d21248c9b1
hystrix:
  command:
    default:
      execution:
        isolation:
          strategy: SEMAPHORE #加上这个就可以获取到HttpServletRequest
          thread:
            timeoutInMilliseconds: 10000

ribbon:    #配置这个为了本地Debug
  ReadTimeout: 60000
  ConnectTimeout: 60000

 

 

******************最好将localhost改为自己的IP**************************************

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值