【问题标题】:Spring Cloud Config - config loaded twice and without profileSpring Cloud Config - 配置加载两次且没有配置文件
【发布时间】:2022-11-06 03:42:48
【问题描述】:

我在正确配置 Spring Cloud 配置时遇到问题。我有依赖

<spring.cloud.version>2021.0.3</spring.cloud.version>

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-config</artifactId>
</dependency>

<dependency>
  <groupId>org.springframework.cloud</groupId>
  <artifactId>spring-cloud-starter-bootstrap</artifactId>
</dependency>

引导程序.yml

spring:
  application.name: myapp
  profiles:
    active: dev
  config:
    import: optional:configserver:http://ip:8888
  cloud:
    config:
      enabled: true
      username: admin
      password: secret

现在,当我的应用程序启动时,它会加载两次配置。第一次加载是按ConfigServicePropertySourceLocator 类进行的,并且没有预期的配置文件。第二个是ConfigServerConfigDataLoader,这次是正确的配置文件。似乎在第一次加载期间加载的配置优先,我的应用程序没有启动。

12:32:54 [ConfigServicePropertySourceLocator:241] - Fetching config from server at : http://ip:8888
12:32:54 [ConfigServicePropertySourceLocator:165] - Located environment: name=myapp, profiles=[default], label=null, version=7d2bc5d68acd8fcca65f34f2074b1860f36e19c6, state=null
12:32:54 [MyApplication:646] - The following 1 profile is active: "dev"
12:32:54 [ConfigServerConfigDataLoader:255] - Fetching config from server at : http://ip:8888
12:32:54 [ConfigServerConfigDataLoader:255] - Located environment: name=myapp, profiles=[dev], label=null, version=7d2bc5d68acd8fcca65f34f2074b1860f36e19c6, state=null

使用参数-Dspring.profiles.active=dev 提供配置文件没有帮助。如何配置boostrap可以读取的配置文件?

【问题讨论】:

    标签: spring-boot spring-cloud-config


    【解决方案1】:

    添加文件资源 -> bootstrap.properties

    spring.application.name=myapp
    spring.profiles.active=dev
    # ip and port of the config server
    spring.cloud.config.uri=http://localhost:8888
    

    【讨论】:

      猜你喜欢
      • 2022-12-04
      • 1970-01-01
      • 1970-01-01
      • 2015-07-13
      • 2019-03-20
      • 2022-01-20
      • 2016-07-29
      • 2016-02-27
      • 2021-01-29
      相关资源
      最近更新 更多