学成在线——关于nacos配置优先级的坑
出错:
本地要起两个微服务,一个是content-api
,另一个是gateway
网关服务。
发现通过网关服务请求content微服务时,怎么请求都请求不到。
配置如下:
content-api-dev.yaml的配置:
server:servlet:context-path: /contentport: 63040test_config:a: 3ab: 3b#配置本地优先
spring:cloud:config:override-none: true
gateway-dev.yaml的配置文件
server:port: 63010 # 网关端口
spring:cloud:gateway:
# filter:
# strip-prefix:
# enabled: trueroutes: # 网关路由配置- id: content-api # 路由id,自定义,只要唯一即可# uri: http://127.0.0.1:8081 # 路由的目标地址 http就是固定地址uri: lb://content-api # 路由的目标地址 lb就是负载均衡,后面跟服务名称predicates: # 路由断言,也就是判断请求是否符合路由规则的条件- Path=/content/** # 这个是按照路径匹配,只要以/content/开头就符合要求
# filters:
# - StripPrefix=1- id: system-api# uri: http://127.0.0.1:8081uri: lb://system-apipredicates:- Path=/system/**
# filters:
# - StripPrefix=1- id: media-api# uri: http://127.0.0.1:8081uri: lb://media-apipredicates:- Path=/media/**
# filters:
# - StripPrefix=1- id: search-service# uri: http://127.0.0.1:8081uri: lb://searchpredicates:- Path=/search/**
# filters:
# - StripPrefix=1- id: auth-service# uri: http://127.0.0.1:8081uri: lb://auth-servicepredicates:- Path=/auth/**
# filters:
# - StripPrefix=1- id: checkcode# uri: http://127.0.0.1:8081uri: lb://checkcodepredicates:- Path=/checkcode/**
# filters:
# - StripPrefix=1- id: learning-api# uri: http://127.0.0.1:8081uri: lb://learning-apipredicates:- Path=/learning/**
# filters:
# - StripPrefix=1- id: orders-api# uri: http://127.0.0.1:8081uri: lb://orders-apipredicates:- Path=/orders/**
# filters:
# - StripPrefix=1
坑:本地的xuecheng-plus-base的配置:
spring.application.name=xuecheng-plus-base
问题就出在这里:
由于后面的content-api服务依赖这个xuecheng-plus-base
,然后又配置了本地优先级最高,因此会将content-api
微服务都放到xuecheng-plus-base
下:
解决办法:
注释掉下面shit这句: