当前位置:网站首页>Nacos搭建配置中心出现client error: invalid param. endpoint is blank
Nacos搭建配置中心出现client error: invalid param. endpoint is blank
2022-07-25 09:15:00 【zulj131】
问题展示:

场景:
在当前项目中,想通过nacos作为配置中心,获取到nacos中存放的配置,因此我加入了以下依赖
<dependencies>
<!--这里是groupId = com.alibaba.cloud 的nacos依赖-->
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-config</artifactId>
</dependency>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-starter-alibaba-nacos-discovery</artifactId>
</dependency>
<!--这里是groupId = com.alibaba.boot 的nacos依赖-->
<dependency>
<groupId>com.alibaba.boot</groupId>
<artifactId>nacos-config-spring-boot-starter</artifactId>
<version>0.2.1</version>
</dependency>
<dependency>
<groupId>org.apache.commons</groupId>
<artifactId>commons-lang3</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>com.alibaba.cloud</groupId>
<artifactId>spring-cloud-alibaba-dependencies</artifactId>
<version>2.2.7.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
首先,先不管为什么alibaba开发者需要把nacos分成groupId = com.alibaba.cloud 和groupId = com.alibaba.boot两种依赖。
我虽然先使用了groupId = com.alibaba.cloud的依赖,而且已经在application.yml中配置了nacos的服务地址。
server:
servlet:
context-path: /mdc-mvc-demo
port: 8081
spring:
application:
name: mdc-mvc-demo
cloud:
nacos:
config:
enable: true # 使用是否配置自动更新
server-addr: 127.0.0.1:8848
group: DEFAULT_GROUP # 组,默认为 DEFAULT_GROUP
file-extension: yaml # 配置内容的数据格式,默认为 properties
但是我参照网络教程的例子,使用的@NacosPropertySource注解是需要使用到groupId = com.alibaba.boot的依赖。
改好了pom.xml之后,我就兴高采烈的启动了,结果启动失败,抛出了上面展示的那个错误。
分析原因:
首先,能够确定的是,是由于@NacosPropertySource引起的问题。
刚开始确实没有什么头绪,于是我从上面打印的日志开始找原因,我注意到某个日志:
22:12:29.077 [main] WARN NacosPropertySourceBuilder -Ignore the empty nacos configuration and get it based on dataId[mdc-mvc-demo] & group[DEFAULT_GROUP]
为什么会提示我nacos的配置为空呢?而且我的dataId是设置为mdc-mvc-demo.yaml,它锁打印的dataId[mdc-mvc-demo] 只是基于spring.application.name设置的默认值。
@Data
@Component
@NacosPropertySource(dataId = "mdc-mvc-demo.yaml", autoRefreshed = true)
public class NacosAnotherProperties {
@NacosValue(value = "${project.name}", autoRefreshed = true)
private String name;
@NacosValue(value = "${project.org}", autoRefreshed = true)
private String org;
}
因此,我推测,是由于groupId = com.alibaba.cloud 和groupId = com.alibaba.boot两种依赖并不是使用同一套配置,groupId = com.alibaba.boot这一套依赖使用的配置是com.alibaba.boot.nacos.config.properties.NacosConfigProperties
于是,我尝试添加了配置:
server:
servlet:
context-path: /mdc-mvc-demo
port: 8081
spring:
application:
name: mdc-mvc-demo
# cloud:
# nacos:
# config:
# enable: true # 使用是否配置自动更新
# server-addr: 127.0.0.1:8848
# group: DEFAULT_GROUP # 组,默认为 DEFAULT_GROUP
# file-extension: yaml # 配置内容的数据格式,默认为 properties
# prefix: 不配置默认是spring.application.name
nacos:
config:
server-addr: 127.0.0.1:8848
后来尝试,@NacosPropertySource不能解析yaml类型的配置,这里改成properties
@Data
@Component
@NacosPropertySource(dataId = "mdc-mvc-demo", autoRefreshed = true)
public class NacosAnotherProperties {
@NacosValue(value = "${project.name}", autoRefreshed = true)
private String name;
@NacosValue(value = "${project.org}", autoRefreshed = true)
private String org;
}
再次启动后,就没有再提示endpoint is blank的报错了,而且也能读取到nacos的配置
解决问题
因此,解决问题的方法是:
如果使用groupId = com.alibaba.boot这种依赖的功能的话,应该使用nacos.config进行配置nacos
边栏推荐
- 酷炫canvas动画冲击波js特效
- Leetcode-238. product of arrays other than itself
- [SCADA case] myscada helps VIB company realize the modernization and upgrading of production line
- Troubleshooting error: NPM install emojis list failed
- How to use pixi.js to make simple Parkour games
- Illustration leetcode - 1184. Distance between bus stops (difficulty: simple)
- How to connect tdengine with idea database tool?
- The garbage classification data set used in the excellent Yolo target detection training is shared - about 3000 labeled
- Disable module (attribute node) in LabVIEW
- This ten-year content industry infrastructure company is actually an invisible Web3 pioneer
猜你喜欢

uni-app - Refused to display ‘xxx‘ in a frame because an ancestor violates the following Content Sec
![[stl]list Simulation Implementation](/img/92/2a78382700c1ebf299c6505d962c9c.png)
[stl]list Simulation Implementation

Do you know these methods of MySQL database optimization?

酷炫canvas动画冲击波js特效
![[machine learning] Finally, the important steps of machine learning modeling have been clarified](/img/75/07767ed694502f0c910d35e1447499.jpg)
[machine learning] Finally, the important steps of machine learning modeling have been clarified

Illustration leetcode - 919. Complete binary tree inserter (difficulty: medium)

对称式加密与非对称式加密的对比

Redis/Mysql知识概述

LabVIEW experiment - temperature detection system (experimental learning version)

centos更改mysql数据库目录
随机推荐
Ctfhub skill tree Web
Robot jumping problem
Sticky.js page scrolling div fixed position plug-in
Ten thousand words long, one word thoroughly! Finally, someone has made business intelligence (BI) clear
28.插槽
Troubleshooting error: NPM install emojis list failed
防抖与节流
Illustration leetcode - 1184. Distance between bus stops (difficulty: simple)
图解LeetCode——1184. 公交站间的距离(难度:简单)
Disable module (attribute node) in LabVIEW
Unity ugui interaction (new ideas)
富文本样式文字图片处理
js触屏小游戏源码冰雪之旅
What is steel grating?
附加:在在下部分区/县(数据表)
activemq--可持久化机制
activemq--持久化机制之LevelDB
51 single chip microcomputer key control LED light status
超赞的yolo目标检测训练所用垃圾分类数据集共享——标注好的约3000张
The development of art NFT