Spring cloud alibaba-遇见的一些小问题

配置文件如下,注:服务发现什么配置我都是放在配置中心里面的

spring:
  application:
    #f服务名称
    name: gateway-service

  cloud:
    nacos:
      config:
        #配置中心地址
        server-addr: 127.0.0.1:8848
        #配置文件格式
        file-extension: yml
        #命名空间
        namespace: dev

    gateway:
      routes:
        #路由ID
      - id: order-service
        #符合路由规则后访问的地址 
        #第一种:ws(websocket)方式: uri: ws://localhost:9000
        #第二种:http方式: uri: http://localhost:8130/
        #第三种:lb(注册中心中服务名字)方式: uri: lb://order-service
        uri: lb://order-service
        predicates:
        #此处通过符合查询参数进行跳转uri
        #如http://localhost:88/order/create?url=baz
        - Query=url,baz

 

第一个问题:版本不一致问题

springboot2.2.2.RELEASE对应的Spring cloud alibaba是2.1.0.RELEASE ,spring cloud 是Hoxton.SR1

具体参考官网:https://start.spring.io/actuator/info

第二个问题:Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency.

在gateway.pom文件里面移除

<dependency>
    <groupId>org.springframework.boot</groupId>
    <artifactId>spring-boot-starter-web</artifactId>
</dependency>

第一个问题:Invalid host: lb://order_service
这个问题是因为既然是以lb的方式访问,那么能被这种方式识别到的命名规则一定要满足“a-zA-Z:.”,而我这里加了“_”,所以出现此错误

 

参考:

gateway:https://cloud.tencent.com/developer/article/1403887

nacos:https://github.com/alibaba/spring-cloud-alibaba/blob/master/README-zh.md

 

 

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
`spring-cloud-alibaba-dependencies`是一个Maven BOM(Bill of Materials),包含了Spring Cloud Alibaba的所有依赖版本。通过引入`spring-cloud-alibaba-dependencies`,可以简化Spring Cloud Alibaba项目的依赖管理。它提供了以下依赖: - `spring-cloud-alibaba-dependencies`:Spring Cloud Alibaba版本管理器 - `spring-cloud-starter-alibaba-nacos-discovery`:Nacos服务发现 - `spring-cloud-starter-alibaba-nacos-config`:Nacos配置中心 - `spring-cloud-starter-alibaba-sentinel`:Sentinel限流熔断 - `spring-cloud-starter-alibaba-seata`:Seata分布式事务 - `spring-cloud-starter-alibaba-rocketmq`:RocketMQ消息队列 - `spring-cloud-starter-alibaba-dubbo`:Dubbo远程调用 使用`spring-cloud-alibaba-dependencies`需要在`pom.xml`文件中引入如下配置: ```xml <dependencyManagement> <dependencies> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-alibaba-dependencies</artifactId> <version>2.2.1.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> ``` 引入该依赖后,其他Spring Cloud Alibaba组件的依赖版本就可以省略了。例如,使用Nacos作为服务发现和配置中心,只需要引入以下依赖: ```xml <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId> </dependency> <dependency> <groupId>com.alibaba.cloud</groupId> <artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId> </dependency> ``` Spring Cloud Alibaba会自动使用`spring-cloud-alibaba-dependencies`中定义的版本。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值