spring cloud 配置中心客户端启动遇到的问题

 更新时间:2021年09月25日 09:18:04   作者:qq_36481502  
这篇文章主要介绍了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的配置如下

以上为个人经验,希望能给大家一个参考,也希望大家多多支持脚本之家。

相关文章

  • 一篇文章带你了解JAVA结构化编程详情

    一篇文章带你了解JAVA结构化编程详情

    下面小编就为大家带来一篇讲解JAVA结构化编程的文章。小编觉得挺不错的,现在就分享给大家,也给大家做个参考。一起跟随小编过来看看吧
    2021-09-09
  • Java获取年月日(格式:xxxx年xx月xx日)的方法详解

    Java获取年月日(格式:xxxx年xx月xx日)的方法详解

    在开发应用程序时,经常需要获取当前的年、月、日,并以特定格式进行展示或处理,本文将介绍如何获取年月日,并将其格式化为“xxxx年xx月xx日”的形式,帮助你在应用程序中处理日期信息,需要的朋友可以参考下
    2023-10-10
  • SpringBoot集成Mybatis-Plus多租户架构实现

    SpringBoot集成Mybatis-Plus多租户架构实现

    本文主要介绍了SpringBoot集成Mybatis-Plus多租户架构实现,文中通过示例代码介绍的非常详细,具有一定的参考价值,感兴趣的小伙伴们可以参考一下
    2021-09-09
  • Sentinel整合Feign流程详细讲解

    Sentinel整合Feign流程详细讲解

    要想整合Feign,首先要了解Feign的使用以及执行过程,然后看 Sentinel如何整合进去,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2022-08-08
  • 如何利用Spring把元素解析成BeanDefinition对象

    如何利用Spring把元素解析成BeanDefinition对象

    这篇文章主要介绍了如何利用Spring把元素解析成BeanDefinition对象,文章围绕主题展开详细的内容介绍,具有一定的参考价值,需要的小伙伴可以参考一下
    2022-08-08
  • springboot如何解决非controller类引用service的问题

    springboot如何解决非controller类引用service的问题

    这篇文章主要介绍了springboot如何解决非controller类引用service的问题,具有很好的参考价值,希望对大家有所帮助。如有错误或未考虑完全的地方,望不吝赐教
    2022-02-02
  • Java开发利器之Guava Cache的使用教程

    Java开发利器之Guava Cache的使用教程

    缓存技术被认为是减轻服务器负载、降低网络拥塞、增强Web可扩展性的有效途径之一。今天咱们就来聊聊Guava Cache本地缓存,感兴趣的可以了解一下
    2022-09-09
  • Java 中利用泛型和反射机制抽象DAO的实例

    Java 中利用泛型和反射机制抽象DAO的实例

    这篇文章主要介绍了Java 中利用泛型和反射机制抽象DAO的实例的相关资料,需要的朋友可以参考下
    2017-07-07
  • 详解Java异常处理的使用与思考

    详解Java异常处理的使用与思考

    异常处理的概念起源于早期的编程语言,如 LISP、PL/I 和 CLU。这些编程语言首次引入了异常处理机制,以便在程序执行过程中检测和处理错误情况。本文主要来介绍一下Java中的异常处理,需要的可以参考一下
    2023-04-04
  • java多线程教程之如何使用线程池详解

    java多线程教程之如何使用线程池详解

    这篇文章主要给大家介绍了关于java多线程之如何使用线程池的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
    2018-11-11

最新评论