SpringCloud遇到的各种问题

1,首先就是SpringBoot和SpringCloud之间的版本兼容问题,以下是我的配置,

<properties>
    <junit.version>4.12</junit.version>
    <spring-cloud.version>Greenwich.RELEASE</spring-cloud.version>
</properties>

<parent>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-parent</artifactId>
    <version>2.1.3.RELEASE</version>
    <relativePath/>
</parent>

2,如果使用Feign中的断路器,就需要在配置文件中添加(使用的是.yml)

feign:
  hystrix:
    enabled: true   #打开Feign自带的断路器

比如

@FeignClient(value = "user",fallback = USerServiceHystric.class)
public interface UserService {

    @RequestMapping(value = "/getUser",method = RequestMethod.GET)
    String get();

}

调用的是user服务的getUser方法(也是一个服务调用另一个服务的其中一种方法),就需要在user服务的配置文件中添加

最后记得实现接口,方法应该覆盖get()方法,就会在user服务挂了的时候执行,而不会大量请求卡在此处,从而调用它的服务也会挂掉

 

3,整合mybatis(使用的是.yml)

spring:
  application:
    name: user  #服务名称
  datasource:
    username: root
    password: 111111
    url: jdbc:mysql://localhost:3306/springboot?useSSL=false&serverTimezone=UTC

serverTimezone=UTC   Mysql时区问题会出现乱码

4,使用路由网关zuul,(使用的是.yml)

启动类需要的注解

@SpringBootApplication
@EnableZuulProxy
@EnableEurekaClient
@EnableDiscoveryClient

配置文件中添加

zuul:
  routes:
    api-a:
      path: /api-user/**
      serviceId: user
    api-b:
      path: /api-feign/**
      serviceId: feign

比如请求的是 http://localhost:8889/api-user/getUser   就相当于请求的是http://localhost:8763/getUser     8763是user服务的端口,请求 http://localhost:8889/api-feign/get    就相当于请求的是http://localhost:8888/get    8888是feign服务的端口

 

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值