gateway路由转发404
问题:
配好gateway后,通过gateway软件系统定制开发的端口请求url出现404,软件系统定制开发并且已经注册到服务列表。
最后发现是maven依赖引用不对。
分析:
排除是路由地址本事出现问题,我们换成百度测试,下面是我配置的yml:
spring: application: name: crmgateway profiles: active: dev #激活dev的配置,nacos配置到 bootstrap.yml cloud: sentinel: transport: #配置 Sentinel dashboard 地址 dashboard: localhost:8080 eager: true gateway: discovery: locator: enabled: false routes: - id: server_finance uri: http://www.baidu.com #用百度做转发测试 predicates: - Path=/**
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
- 11
- 12
- 13
- 14
- 15
- 16
- 17
- 18
- 19
- 20
- 21
换成 http://www.baidu.com 依然请求404,甚是不解。
好在环节不多,从头梳理。
解决:
先看 maven 依赖,发现这个依赖与其它参考文档有点不同,这个是新建项目时勾选自动依赖上的
替换成 spring-cloud-starter-gateway 运行测试
运行失败控制台打印出:
Spring MVC found on classpath, which is incompatible with Spring Cloud Gateway at this time. Please remove spring-boot-starter-web dependency.
- 1
那就把这个web依赖去掉:
服务启动成功,我们通过访问localhost:8001 路由转发到了 www.baidu.com,问题成功解决。
如果解决了你的问题,记得点个赞哦!
依赖如下,拿去用,版本对应自己的版本:
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-gateway</artifactId> <version>${spring-cloud-alibaba.version}</version> </dependency>
- 1
- 2
- 3
- 4
- 5