springCloud配置文件

常用配置 application.yml配置文件

#eureka客户端配置
eureka:
  server:
    ip: 127.0.0.1
    port: 16000
  instance:
    prefer-ip-address: true
    #每间隔2s,向服务端发送一次心跳,证明自己依然”存活“
    lease-renewal-interval-in-seconds: 2
    #告诉服务端,如果我4s之内没有给你发心跳,就代表我“死”了,将我踢出掉
    lease-expiration-duration-in-seconds: 4
  client:
    register-with-eureka: true
    fetch-registry: true
    serviceUrl:
      defaultZone: http://${eureka.server.ip}:${eureka.server.port}/eureka/
#http请求客户端负载均衡各项配置
feign:
  #开启客户端熔断机制
  hystrix:
    enabled: true
  #开启请求和响应的压缩机制(GZIP)
  compression:
    request:
      enabled: true
    response:
      enabled: true
#zuul转发规则配置
zuul:
  #关闭请求转发重试机制(全局关闭)
  retryable: false
  #添加默认前缀
  prefix: /api
  #不移除前缀
  strip-prefix: true
  #重新定义敏感请求头信息,放行全部的请求头部信息
  sensitive-headers:
  #解决重定向跳转路径问题(这个配置没什么卵用)
  add-host-header: true
  #配置路由git
  routes:
    ws_auth:
      path: /ws_auth/**
      serviceId: ws-auth
      strip-prefix: true
#ribbon的全局配置项
ribbon:
  #http请求连接建立超时时间(ms)
  ConnectTimeout: 5000
  #http请求处理超时时间(ms)
  ReadTimeout: 15000
  #默认重试次数
  MaxAutoRetries: 1
  #默认尝试的实例数
  MaxAutoRetriesNextServer: 2

#熔断机制配置
#熔断的超时时间(ms)
hystrix:
  command:
    default:
      execution:
        isolation:
          thread:
            timeoutInMilliseconds: 15000
          #线程隔离策略配置,官方推荐使用THREAD,即下游依赖的请求在一个单独的线程中隔离,这里为了解决feign转发时需要携带head信息所以讲策略设置为SEMAPHORE,即下游依赖请求在当前调用线程中执行
          strategy: SEMAPHORE
在这里插入代码片
Spring Cloud可以使用Nacos作为注册中心。下面是在Spring Cloud项目中注册Nacos的步骤: 1. 添加Nacos依赖:在项目的pom.xml文件中添加Nacos的依赖项,例如: ```xml <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> ``` 2. 配置Nacos注册中心:在项目的配置文件(例如application.properties或application.yml)中配置Nacos注册中心的地址和其他相关配置,例如: ```yaml spring: cloud: nacos: discovery: server-addr: localhost:8848 ``` 3. 启用Nacos注册中心:在Spring Boot应用程序的启动类上添加`@EnableDiscoveryClient`注解,例如: ```java import org.springframework.boot.SpringApplication; import org.springframework.boot.autoconfigure.SpringBootApplication; import org.springframework.cloud.client.discovery.EnableDiscoveryClient; @SpringBootApplication @EnableDiscoveryClient public class YourApplication { public static void main(String[] args) { SpringApplication.run(YourApplication.class, args); } } ``` 4. 注册服务:在Spring Boot应用程序的其他组件或服务上使用`@RestController`或`@Service`注解,并使用`@Value`注解注入需要注册的服务信息,例如: ```java import org.springframework.beans.factory.annotation.Value; import org.springframework.web.bind.annotation.GetMapping; import org.springframework.web.bind.annotation.RestController; @RestController public class YourController { @Value("${spring.application.name}") private String applicationName; @GetMapping("/hello") public String hello() { return "Hello from " + applicationName;
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值