共计 641 个字符,预计需要花费 2 分钟才能阅读完成。
今天在搭建 spring cloud alibaba 架子,在添加好 gateway 模块后,我尝试使用它调用注册到 nacos 中的服务,这个子服务的 application.name 我设置为了 atlas-data,context-path 也设置为了 atlas-data,然后 Gateway 的配置如下:
server:
port: 8888
servlet:
context-path: /
spring:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
gateway:
routes:
- id: atlas-data
uri: lb://atlas-data
predicates:
- Path=/atlas-data/**
discovery:
locator:
enabled: true
lower-case-service-id: true
application:
name: atlas-gateway
然后我通过请求:http://localhost:8888/atlas-data/api/xxx 的一些接口都报 404,纳闷了很久,因为我没想到是因为同名导致的问题。
然后我尝试将请求链接改为:http://localhost:8888/atlas-data/atlas-data/api/xxx 后发现可以请求。
我懵逼了……
后来发现是 application.name 和 context-path 同名导致的,有小伙伴知道具体原因吗?为什么同名后写两次 context-path 才可以请求到。
正文完