spring cloud 配置中心客户端启动遇到的问题
作者:qq_36481502 发布时间:2023-03-23 16:30:34
标签:spring,cloud,配置,客户端,启动
spring cloud 配置中心客户端启动
先启动了配置中心,然后启动客户端,
发现打印的日志是这样的
2020-04-29 11:13:02.333 INFO 1856 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:9009/
2020-04-29 11:13:08.121 INFO 1856 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=test-config, profiles=[dev], label=master, version=3eb2b779d066af89af4ba5b7a722d2189a15ffd3, state=null
2020-04-29 11:13:08.122 INFO 1856 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}, BootstrapPropertySource {name='bootstrapProperties-https://github.com/kzdw/springCloudConfigCenter.git/test-config.yml (document #1)'}, BootstrapPropertySource {name='bootstrapProperties-https://github.com/kzdw/springCloudConfigCenter.git/test-config.yml (document #0)'}]
2020-04-29 11:13:08.127 INFO 1856 --- [ main] c.z.c.ConfigCloudClientApplication : The following profiles are active: dev
2020-04-29 11:13:08.408 INFO 1856 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=3bad3006-6836-326e-9ae4-7b60b788ec28
2020-04-29 11:13:08.720 INFO 1856 --- [ main] c.z.c.ConfigCloudClientApplication : Started ConfigCloudClientApplication in 7.436 seconds (JVM running for 8.236)
从日志上看,已经获取到了配置中心的配置,但是呢,总感觉日志不对,怎么就没有启动的端口呢。
springcloud经常会一个模块包含另外模块,难道web模块没有被 spring-cloud-starter-config 包含?
那就加入web模块吧
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
加入之后再启动项目
2020-04-29 11:20:35.379 INFO 10060 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:9009/
2020-04-29 11:20:36.849 INFO 10060 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=test-config, profiles=[dev], label=master, version=3eb2b779d066af89af4ba5b7a722d2189a15ffd3, state=null
2020-04-29 11:20:36.850 INFO 10060 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: [BootstrapPropertySource {name='bootstrapProperties-configClient'}, BootstrapPropertySource {name='bootstrapProperties-https://github.com/kzdw/springCloudConfigCenter.git/test-config.yml (document #1)'}, BootstrapPropertySource {name='bootstrapProperties-https://github.com/kzdw/springCloudConfigCenter.git/test-config.yml (document #0)'}]
2020-04-29 11:20:36.855 INFO 10060 --- [ main] c.z.c.ConfigCloudClientApplication : The following profiles are active: dev
2020-04-29 11:20:37.278 INFO 10060 --- [ main] o.s.cloud.context.scope.GenericScope : BeanFactory id=21eb9db3-9e16-3c20-bd81-2c0ea23b0f12
2020-04-29 11:20:37.566 INFO 10060 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8201 (http)
2020-04-29 11:20:37.574 INFO 10060 --- [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat]
2020-04-29 11:20:37.574 INFO 10060 --- [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.33]
2020-04-29 11:20:37.684 INFO 10060 --- [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext
2020-04-29 11:20:37.684 INFO 10060 --- [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 817 ms
2020-04-29 11:20:37.851 INFO 10060 --- [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService 'applicationTaskExecutor'
2020-04-29 11:20:38.200 INFO 10060 --- [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8201 (http) with context path ''
2020-04-29 11:20:38.285 INFO 10060 --- [ main] c.z.c.ConfigCloudClientApplication : Started ConfigCloudClientApplication in 3.87 seconds (JVM running for 4.531)
果然,从配置中心拉取到了配置并成功启动了。
spring cloud配置中心客户端配置的坑
1. 出错信息如下
在启动配置中心的客户端时,报以下错误信息:
Caused by: java.lang.IllegalArgumentException: Could not resolve placeholder 'foo' in value "${foo}"
2. 度娘查了下,发现很多人碰到这个坑
首先我提交到git上到配置文件名称为下面两个文件
cloud-config-dev.properties
cloud-config-test.properties
遵循配置中心配置文件的规则/{application}-{profile}.properties
所以在cloud-config-client端调用的时候,applcation.name应该是cloud-config,然而我在配置的时候,想当然的写成了cloud-config-client,导致出现上面的错误。
解决方法很简单,贴下client的配置如下
以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。
来源:https://blog.csdn.net/qq_36481502/article/details/105835515
0
投稿
猜你喜欢
- Spring AOP proxyTargetClass的行为要点列表形式proxyTargetClasstrue目标对象实现了接口 – 使用
- Java读取txt文件内容。可以作如下理解:首先获得一个文件句柄。File file = new File(); file即为文件句柄。两人
- maven依赖及一些配置这里主要是搭建项目常用到的maven依赖以及搭建项目会需要用到的一些配置文件,可能下面这些依赖还不是很全,但是应该会
- Handler是什么?Handler 是一个可以实现多线程间切换的类,通过 Handler 可以轻松地将一个任务切换到 Handler 所在
- IDEA设置文档注释模板创建Class文件时自动生成的头部注释如图如何配置idea的头部注释格式,可以生成像之前的注释格式一样的文档注释?F
- SpringMVC @RequestBody的使用Spring mvc是一个非常轻量的mvc框架,注解可以大大减少配置,让请求的拦截变得比较
- IntInt是Java八种基本数据类型之一,一般大小为4字节32位,取值范围为2-31—231。两个Int类型变量用“==”比较的是值的大小
- 样例代码在讲 Flutter 的盒子模型前,先看看HTML 中的盒子模型。如下图所示,一个页面元素包括了与父级容器的外边距(margin),
- 在文件夹中,我们经常有类似s_1.txt、s_2.txt、s_10.txt、s_11.txt这样的命名方式,我们期望的排序方式是s_1.tx
- 提几个问题,从问题中去了解去学习:他们之间有啥区别?如果我使用notify(),将通知哪个线程?我怎么知道有多少线程在等待,所以我可以使用n
- 前言Zuul 是Netflix 提供的一个开源组件,致力于在云平台上提供动态路由,监控,弹性,安全等边缘服务的框架。也有很多公司使用它来作为
- 前言使用SpringBoot来开发项目相对于传统模式,要快速优雅许多,相信目前国内绝大部分web项目的开发还没有使用SpringBoot来做
- Javaweb分页技术实现分页技术就是通过SQL语句(如下)来获取数据,具体实现看下面代码//分页查询语句select * from 表名
- switch结构(开关语句)的语法switch(表达式 ){--->类型为int、char case 常量1 :---&g
- 定义:动态给一个对象添加一些额外的职责,就象在墙上刷油漆.使用Decorator模式相比用生成子类方式达到功能的扩充显得更为灵活。设计初衷:
- 现在许多系统的注册、登录或者发布信息模块都添加的随机码功能,就是为了避免自动注册程序或者自动发布程序的使用。验证码实际上就是随机选择一些字符
- 关于UIToolbarToolBar工具栏是视图View的属性,可以在工具栏上添加工具栏按钮Bar Button Item(可以是自定义的C
- 直接调用HashKit.sha1(String str)方法就可以了,,返回的是16进制的字符串长度是40,也就是用md.digest()方
- 你是否受够了每次修改静态文件都要重启服务器?有时候在一些公司前后端的职责没有那么的明确,往往后台人员也要去写一些页面,像jsp页面,或者其他
- 一、何为栈?栈(stack)又名堆栈,它是一种运算受限的线性表。限定仅在表尾进行插入和删除操作的线性表。这一端被称为栈顶,相对地,把另一端称