分布式配置中心config-client配置报错:java.lang.IllegalStateException: duplicate key: spring

今天练习分布式配置中心,写config-client配置文件,使用bootstrap.properties配置,运行没有问题。

bootstrap.properties:

spring.application.name=config-client
spring.cloud.config.label=master
spring.cloud.config.profile=dev
spring.cloud.config.uri= http://localhost:8888/
server.port=8881

#spring.cloud.config.label 指明远程仓库的分支

#spring.cloud.config.profile

#dev开发环境配置文件
#test测试环境
#pro正式环境
#spring.cloud.config.uri= http://localhost:8888/ 指明配置服务中心的网址。

#spring.cloud.config.discovery.enabled 是从配置中心读取文件。
#spring.cloud.config.discovery.serviceId 配置中心的servieId,即服务名

但是我使用了bootstrap.yml配置文件,启动报错:

bootstrap.yml:

spring:
  application:
    name: config-client
server:
  port: 8881

spring:
  cloud:
    config:
      label: master
      profile: dev
      uri: http://localhost:8888/

报错如下:

java.lang.IllegalStateException: Failed to load property source from location ‘classpath:/bootstrap.yml‘
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:538)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadForFileExtension(ConfigFileApplicationListener.java:497)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:465)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$null$6(ConfigFileApplicationListener.java:447)
    at java.lang.Iterable.forEach(Unknown Source)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.lambda$load$7(ConfigFileApplicationListener.java:446)
    at java.lang.Iterable.forEach(Unknown Source)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:443)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:335)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.addPropertySources(ConfigFileApplicationListener.java:214)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.postProcessEnvironment(ConfigFileApplicationListener.java:197)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEnvironmentPreparedEvent(ConfigFileApplicationListener.java:184)
    at org.springframework.boot.context.config.ConfigFileApplicationListener.onApplicationEvent(ConfigFileApplicationListener.java:170)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:358)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:317)
    at org.springframework.boot.builder.SpringApplicationBuilder.run(SpringApplicationBuilder.java:137)
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.bootstrapServiceContext(BootstrapApplicationListener.java:197)
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:104)
    at org.springframework.cloud.bootstrap.BootstrapApplicationListener.onApplicationEvent(BootstrapApplicationListener.java:70)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.doInvokeListener(SimpleApplicationEventMulticaster.java:172)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.invokeListener(SimpleApplicationEventMulticaster.java:165)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:139)
    at org.springframework.context.event.SimpleApplicationEventMulticaster.multicastEvent(SimpleApplicationEventMulticaster.java:127)
    at org.springframework.boot.context.event.EventPublishingRunListener.environmentPrepared(EventPublishingRunListener.java:74)
    at org.springframework.boot.SpringApplicationRunListeners.environmentPrepared(SpringApplicationRunListeners.java:54)
    at org.springframework.boot.SpringApplication.prepareEnvironment(SpringApplication.java:358)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:317)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1255)
    at org.springframework.boot.SpringApplication.run(SpringApplication.java:1243)
    at cn.itcast.com.ConfigClientApplication.main(ConfigClientApplication.java:22)
Caused by: java.lang.IllegalStateException: duplicate key: spring
    at org.yaml.snakeyaml.constructor.SafeConstructor.processDuplicateKeys(SafeConstructor.java:99)
    at org.yaml.snakeyaml.constructor.SafeConstructor.flattenMapping(SafeConstructor.java:70)
    at org.yaml.snakeyaml.constructor.SafeConstructor.constructMapping2ndStep(SafeConstructor.java:182)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructMapping(BaseConstructor.java:443)
    at org.yaml.snakeyaml.constructor.SafeConstructor$ConstructYamlMap.construct(SafeConstructor.java:519)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructObjectNoCheck(BaseConstructor.java:207)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructObject(BaseConstructor.java:196)
    at org.springframework.boot.env.OriginTrackedYamlLoader$OriginTrackingConstructor.constructObject(OriginTrackedYamlLoader.java:94)
    at org.yaml.snakeyaml.constructor.BaseConstructor.constructDocument(BaseConstructor.java:161)
    at org.yaml.snakeyaml.constructor.BaseConstructor.getData(BaseConstructor.java:127)
    at org.yaml.snakeyaml.Yaml$1.next(Yaml.java:547)
    at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:166)
    at org.springframework.beans.factory.config.YamlProcessor.process(YamlProcessor.java:139)
    at org.springframework.boot.env.OriginTrackedYamlLoader.load(OriginTrackedYamlLoader.java:75)
    at org.springframework.boot.env.YamlPropertySourceLoader.load(YamlPropertySourceLoader.java:50)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.loadDocuments(ConfigFileApplicationListener.java:556)
    at org.springframework.boot.context.config.ConfigFileApplicationListener$Loader.load(ConfigFileApplicationListener.java:518)
    ... 35 common frames omitted

报错信息显示无法加载配置文件,原因是重复建“spring”。

解决:yml文件在单一文件中,可用连续三个连字号(---)区分多个文件。更改bootstrap.yml:

spring:
  application:
    name: config-client
server:
  port: 8881
---
spring:
  cloud:
    config:
      label: master
      profile: dev
      uri: http://localhost:8888/

重启,运行成功。

原文地址:https://www.cnblogs.com/saule/p/11569868.html

时间: 2024-10-09 02:17:12

分布式配置中心config-client配置报错:java.lang.IllegalStateException: duplicate key: spring的相关文章

maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener

本篇文章主要介绍了"maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener ",主要涉及到maven web 项目中启动报错java.lang.ClassNotFoundException: org.springframework.web.util.Log4jConfigListener 方面的内容,对于maven web 项目中启动报错jav

Android Studo 使用 JNI报错:java.lang.UnsatisfiedLinkError: Couldn't load XXX from loader dalvik.system.PathClassLoader

今天在使用Android Studio的时候突然发现代码没错,so包也引入了,各个版本都引入了,但是就是一直报错: java.lang.UnsatisfiedLinkError: Couldn't load serphone from loader dalvik.system.PathClassLoader 11-30 11:13:18.766 29255-29255/com.personal.tai.ronglianim E/AndroidRuntime: at java.lang.Runti

jdbc连接sqlserver报错java.lang.ClassNotFoundException: com.microsoft.jdbc.sqlserver.SQLServerDriver

使用2008的数据库, 我已经引入的sqljdbc4的包,单还是报这个错,很奇怪突然想到在配置hibernate的时候,是拷贝下来的代码 然后到网上查了下, 因为是2008的版本驱动和2000的有点不同, 之前的都是可能是2000或者2005的class是com.microsoft.jdbc.sqlserver.SQLServerDriver 可是2008  去是com.microsoft.sqlserver.jdbc.SQLServerDriver 就这么改过来就可以了 jdbc连接sqlse

eclipse下执行wordcount报错 java.lang.ClassNotFoundException 解决办法

eclipse下执行wordcount报错 java.lang.ClassNotFoundException 17/08/29 07:52:54 INFO Configuration.deprecation: fs.default.name is deprecated. Instead, use fs.defaultFS 17/08/29 07:52:54 WARN util.NativeCodeLoader: Unable to load native-hadoop library for y

报错:java.lang.Long cannot be cast to java.lang.Integer

Long 无法转化成Integer类型. 这个异常 经常出现在hinbernate分页查询的时候. 原因: 这里在Hibernate2.0之前版本list.get(0)返回的是Integer类型. 但是在Hibernate3.0以后版本list.get(0)返回的是Long类型. 解决方法 public Integer getUsersCount() { String hql = "select count(*) from Users"; List list = super.pageQ

开着idea,死机了,关机重启。重启之后,重新打开idea报错java.lang.AssertionError:upexpected content storage modification

开着idea,死机了,关机重启.重启之后,重新打开idea报错java.lang.AssertionError:upexpected content storage modification. goole得到: If you cannot even open your project in IntelliJ: Close IntelliJ Go to the directory <your_home>/.IntelliJIdeaXX/system/cache where XX is your

MyEclipse2014报错java.lang.ClassNotFoundException

MyEclipse2014做web开发的时候,总是报错java.lang.ClassNotFoundException.而对应的类有能在包中找到.原因一般是由下面情况引起的. 在开发的时候,我们习惯性的在lib下面根据包类型或作用分文件夹来管理,然后手动将包导入到项目中(此时包会在Referenced Libraries中),而MyEclipse2014只会自动加载Web app Libraries文件夹中的包. 解决办法就是,将所有的支撑包都放到lib目录下,而不要在lib目录下分文件夹管理.

DRP问题集结(一)-Tomcat无法启动,报错java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory

问题一:  Tomcat无法启动,报错java.lang.NoClassDefFoundError: org/apache/juli/logging/LogFactory 问题二:[Error]JavaWeb: 严重: Failed to initialize end point associated with ProtocolHandler ["http-bio-8080"] 问题三:The APR based Apache Tomcat Native library which a

Webservice报错java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.XmlBeanDefinitionRead

用spring集成发布一个Webservice服务,老是报错: java.lang.NoSuchMethodError: org.springframework.beans.factory.xml.XmlBeanDefinitionReader.setValidationMode(I)V at org.apache.xbean.spring.context.v2.XBeanXmlBeanDefinitionReader.<init>(XBeanXmlBeanDefinitionReader.j