当前位置:网站首页>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
边栏推荐
- Ctfhub skill tree Web
- 360度拖拽全景图插件tpanorama.js
- sticksy.js页面滚动div固定位置插件
- Visual query (sp_helptext) -- quick query of stored procedures containing specified strings (with source code)
- [common tools] obtain system status information based on psutil and gputil
- A picture to quickly understand envoyfilter in istio
- How to realize the drop-down option box of wechat applet
- JDBC quick start
- Sort out Huawei ap-3010dn_ V2 configuration create WiFi
- How does Flink SQL persist?
猜你喜欢

sql注入

Ctfhub skill tree Web

(self drawn ugly picture) simple understanding tcp/ip three handshakes and four waves
![[STL]list模拟实现](/img/92/2a78382700c1ebf299c6505d962c9c.png)
[STL]list模拟实现

js触屏小游戏源码冰雪之旅
![[stl]list Simulation Implementation](/img/92/2a78382700c1ebf299c6505d962c9c.png)
[stl]list Simulation Implementation

activemq--延迟投递和定时投递

The garbage classification data set used in the excellent Yolo target detection training is shared - about 3000 labeled

Yolov5 environment configuration

Bi business interview with data center and business intelligence (I): preparation for Industry and business research
随机推荐
A picture to quickly understand envoyfilter in istio
Common tool classes under JUC package
Redis/Mysql知识概述
为什么说DAO是未来的公司形式
How does Flink SQL persist?
SQL injection
The simplest sklearn environment configuration tutorial in the whole network (100% success)
sticksy.js页面滚动div固定位置插件
Opencv realizes simple face tracking
Unity ugui interaction (new ideas)
附加:下半部分sql语句 区/县(数据表)
51 single chip microcomputer controls nixie tube display
优炫数据库对数据的加密是如何做的?
JS pop-up City filtering component matches mobile terminal
Robot jumping problem
Additional: SQL statement area / county in the middle half (data table)
Full solution of JDBC API
centos更改mysql数据库目录
Comparison between symmetric encryption and asymmetric encryption
Silicon Valley classroom lesson 15 - Tencent cloud deployment