1.今天搭建springcloud工程,springboot版本2.4.2,springcloud版本2020.0.0,spring-cloud-alibaba版本2.2.1.RELEASE,使用nacos搭建注册中心和配置中心,结果一个微服务启动后报错,Could not resolve placeholder ‘config.info’ in value "${config.info},调了半天,关于nacos的dataId啥的都检查了半天(关于dataId的坑就在于,如果配置文件使用yml,那么在nacos上的文件后缀必须严格为yaml),没问题,最后定位到是配置文件bootstrap.properties/yml没生效,网上查了下,有好多人说是少了个依赖:
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-context</artifactId>
</dependency>
但是加了依然没屌用,因为时间原因,没法深入研究,直接降版本springboot版本2.2.5.RELEASE,springcloud版本Hoxton.SR4,spring-cloud-alibaba版本2.2.0.RELEASE,就好了。具体原因以后在研究
2.项目中使用gateway作为网关,测试路由都正常:
cloud:
gateway:
routes:
-id: test_route
uri: https://www.baidu.com
predicates:
- Query=url,baidu
访问:http://localhost:88?url=baidu, 但是当前端vue向网关发请求访问后端服务时(前端配置baseUrl为网关地址),出现503 Service Unavailable,经过排查,发现是由于nacos注册中心的namespace导致,注释后就可正常访问:
cloud:
nacos:
discovery:
server-addr: 127.0.0.1:8848
# namespace: ff97d74c-fee4-4492-97ae-bbd01af6d96a
这是注释了网关工程自己注册到nacos上的namespace,然后经由网关路由访问别的微服务,发现也是503,因为那个微服务注册到nacos上有写了namespace,注释掉即可
网友评论