spring-boot - Spring Cloud Config Server - 未获取属性
问题描述
我们正在尝试将 Spring Cloud Config Server 添加到我们的项目中以将配置外部化。
我们创建了一个连接到 Git 存储库的配置服务器,并且似乎工作正常。然而,当我们启动一个示例客户端时,我们会收到一条从服务器获取配置的消息。定位的环境,然后是设置属性的消息,我们在 git repo 的相应 yaml 文件中设置了该属性。
配置服务器 bootStrap.yml
spring:
application:
name: configuration-service
server:
port: 8888
配置服务器 application.yml
spring:
profiles:
active: dev
security:
user:
name: root
password: M5awantk
cloud:
config:
server:
git:
clone-on-start: true
uri: https://git.assembla.com/*********
username: ***********
password: ***********
点击http://localhost:8080/notification-service/default给出以下正确的
{
name: "notification-service",
profiles: [
"default"
],
label: null,
version: "21ee5025b232b812e0e64387cd577eeda0351214",
state: null,
propertySources: [
{
name: "https://git.assembla.com/pins-configuration.git/notification-service.yml",
source: {
spring.main.allow-bean-definition-overriding: true,
spring.application.name: "notification-service",
spring.zipkin.baseUrl: "http://localhost:9411/",
spring.jpa.properties.hibernate.cache.use_second_level_cache: true,
spring.jpa.properties.hibernate.cache.use_query_cache: true,
server.port: 8091,
server.compression.enabled: true,
server.compression.min-response-size: 2048,
server.compression.mime-types: "application/json,application/xml,text/html,text/plain",
eureka.instance.hostname: "localhost",
eureka.instance.port: 8761,
eureka.instance.leaseRenewalIntervalInSeconds: 3,
eureka.instance.instanceId:
"${spring.application.name}:${spring.application.instance_id:${random.value}}",
eureka.client.registryFetchIntervalSeconds: 5,
eureka.client.instanceInfoReplicationIntervalSeconds: 5,
eureka.client.initialInstanceInfoReplicationIntervalSeconds: 5,
eureka.client.serviceUrl.defaultZone:
"http://${eureka.instance.hostname}:${eureka.instance.port}/eureka/"
}
}
]
}
客户端(名为通知服务)
客户端 bootstrap.yml
spring:
cloud:
config:
uri: http://localhost:8888
username: root
password: M5awantk
name: notification-service
application:
name: notifcation-service
在启动通知服务时,它似乎按预期找到了配置服务和 notification-service.yml,但随后出现错误
考虑重命名 bean 之一或通过设置 spring.main.allow-bean-definition-overriding=true 来启用覆盖
尽管我们在 notification-service.yml 中有以下内容,并且当我们点击 http://localhost:8080/notification-service/default时它会显示
spring.main.allow-bean-definition-overriding: true
启动通知服务时的控制台输出
2020-03-24 18:26:03.046 INFO [notifcation-service,,,] 24238 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Fetching config from server at : http://localhost:8888
2020-03-24 18:26:04.847 INFO [notifcation-service,,,] 24238 --- [ main] c.c.c.ConfigServicePropertySourceLocator : Located environment: name=notification-service, profiles=[default], label=null, version=21ee5025b232b812e0e64387cd577eeda0351214, state=null
2020-03-24 18:26:04.848 INFO [notifcation-service,,,] 24238 --- [ main] b.c.PropertySourceBootstrapConfiguration : Located property source: OriginTrackedCompositePropertySource {name='configService', propertySources=[MapPropertySource {name='configClient'}, OriginTrackedMapPropertySource {name='https://git.assembla.com/pins-configuration.git/notification-service.yml'}]}
2020-03-24 18:26:04.900 INFO [notifcation-service,,,] 24238 --- [ main] c.s.p.n.NotificationServiceApplication : The following profiles are active: dev
2020-03-24 18:26:06.237 INFO [notifcation-service,,,] 24238 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-03-24 18:26:06.464 INFO [notifcation-service,,,] 24238 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 217ms. Found 3 JPA repository interfaces.
2020-03-24 18:26:06.474 INFO [notifcation-service,,,] 24238 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Bootstrapping Spring Data JPA repositories in DEFAULT mode.
2020-03-24 18:26:06.615 INFO [notifcation-service,,,] 24238 --- [ main] .s.d.r.c.RepositoryConfigurationDelegate : Finished Spring Data repository scanning in 140ms. Found 21 JPA repository interfaces.
2020-03-24 18:26:06.616 WARN [notifcation-service,,,] 24238 --- [ main] ConfigServletWebServerApplicationContext : Exception encountered during context initialization - cancelling refresh attempt: org.springframework.beans.factory.support.BeanDefinitionOverrideException: Invalid bean definition with name 'jpaAuditingHandler' defined in null: Cannot register bean definition [Root bean: class [org.springframework.data.auditing.AuditingHandler]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] for bean 'jpaAuditingHandler': There is already [Root bean: class [org.springframework.data.auditing.AuditingHandler]; scope=; abstract=false; lazyInit=null; autowireMode=0; dependencyCheck=0; autowireCandidate=true; primary=false; factoryBeanName=null; factoryMethodName=null; initMethodName=null; destroyMethodName=null] bound.
2020-03-24 18:26:06.626 INFO [notifcation-service,,,] 24238 --- [ main] ConditionEvaluationReportLoggingListener :
Error starting ApplicationContext. To display the conditions report re-run your application with 'debug' enabled.
2020-03-24 18:26:06.630 ERROR [notifcation-service,,,] 24238 --- [ main] o.s.b.d.LoggingFailureAnalysisReporter :
***************************
APPLICATION FAILED TO START
***************************
Description:
The bean 'jpaAuditingHandler' could not be registered. A bean with that name has already been defined and overriding is disabled.
Action:
Consider renaming one of the beans or enabling overriding by setting spring.main.allow-bean-definition-overriding=true
不确定我们可能做错了什么。
编辑:我已经设法获得了一个非常简单的应用程序,它只使用相应的 application.yml 中设置的一个属性。
想知道这是否与无法及时提供的属性有关,尽管从控制台输出看来并非如此。
解决方案
推荐阅读
- pycharm - PyCharm:是否可以自动完成这些关键字参数(**kwargs)?
- google-bigquery - 在 bigquery 中了解一个月的周数
- javascript - Laravel 5.3 Elixir Webpack - 不会将 Object.assign 转换为 EcmaScript 2015
- angular - 错误:文档未定义,构建角度通用应用程序
- android - 是否可以在 Google Map 中的标记的一小块区域中收听点击?
- reactjs - React Native 识别对象中的布尔值
- python - 将 Django 模型字段从 TextField 迁移到 ArrayField
- java - Siddhi HTTP NoSuchMethodError
- php - Making database results array into variables php
- android - 反应原生,检测视图屏幕恢复