Nacos集成spring cloud gateway

本文记录了在Spring Cloud Gateway项目中集成Nacos的过程,包括遇到的问题及解决方案。首先,由于Spring Boot的web依赖冲突,导致启动失败,移除该依赖后解决了问题。接着,通过引入Nacos Discovery,实现了服务发现。尽管没有将Gateway注册到Nacos,但请求仍能成功。然而,在整合Feign后,必须启用@EnableDiscoveryClient。此外,POST请求出错是由于POM文件中的依赖冲突,去除特定依赖后问题解决。最后,服务ID在Gateway配置和服务注册中心不一致会导致503错误,调整一致后问题得到解决。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

今天使用Nacos集成spring cloud gateway,记录一下
最开始我创建了一个module :cloud-gateway,并且在pom文件里配置这样(部分代码截取):

 <parent>
        <groupId>com.example</groupId>
        <artifactId>demo</artifactId>
        <version>1.0.0</version>
    </parent>

然后启动的时候,就说已经使用了gateway,让去掉spring-boot-starter-web的依赖,因为我的父级pom里引入了spring-boot-starter-web。

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

然后我就把 改了,

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.3.5.RELEASE</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>cloud-gateway</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>cloud-gateway</name>
    <description>Demo projec
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值