当前位置:网站首页>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
边栏推荐
- Sort out Huawei ap-3010dn_ V2 configuration create WiFi
- Wechat applet obtains the data of ---- onenet and controls the on-board LED of STM32
- sticksy.js页面滚动div固定位置插件
- How to avoid duplicate data when the database is high and distributed
- Kubedm introduction
- 图解LeetCode——1184. 公交站间的距离(难度:简单)
- 360 degree drag panorama plug-in tpanorama.js
- JDBC的api全解
- activemq--可持久化机制之JDBC
- flink sql怎么持久化?
猜你喜欢

nacos2.1.0集群搭建

How to avoid duplicate data when the database is high and distributed
[learn rust together] a preliminary understanding of rust package management tool cargo

JS small game source code magic tower breakthrough Download

This is the worst controller layer code I've ever seen

Shell script

Feiling ok1028a core board adapts to rtl8192cu WiFi module

这家十年内容产业基建公司,竟是隐形的Web3先行者

Silicon Valley class lesson 11 - official account news and wechat authorization

table表格展开内部行切换效果
随机推荐
table表格展开内部行切换效果
2022-7-14 JMeter simulates the login of different users for pressure test
音乐人的 NFT 指南
LabVIEW experiment - temperature detection system (experimental learning version)
Redis sentry, master-slave deployment details
Silicon Valley classroom lesson 15 - Tencent cloud deployment
A picture to quickly understand envoyfilter in istio
Silicon Valley classroom lesson 12 - official account on demand course and live broadcast management module
How to connect tdengine with idea database tool?
How to use pixi.js to make simple Parkour games
Dependency conflict resolution under idea
js小游戏源码魔塔闯关下载
Comparison between symmetric encryption and asymmetric encryption
(self drawn ugly picture) simple understanding tcp/ip three handshakes and four waves
Ten thousand words long, one word thoroughly! Finally, someone has made business intelligence (BI) clear
28.插槽
JS pop-up City filtering component matches mobile terminal
Arcgis10.2 installation tutorial
Redis-哨兵,主从部署详细篇
Composition of the interview must ask items