【问题标题】:spring cloud config client does not load config files. Think the problem may be profile settinsspring cloud config 客户端不加载配置文件。认为问题可能是配置文件设置
【发布时间】:2022-01-20 10:21:39
【问题描述】:

我查看了过去的堆栈跟踪,并且我拥有所有正确的设置。我认为这更多是个人资料的问题。

我没有使用 git 作为数据源,而是使用 S3,但它可以在我运行时在我的本地运行

http://localhost:8086/application/default

返回

{
    "name": "application",
    "profiles": [
        "default"
    ],
    "label": null,
    "version": null,
    "state": null,
    "propertySources": [
        {
            "name": "s3:application",
            "source": {
                "environment.profile": "local",

在我的 pom 上,我已经为 spring boot 设置好了

<parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.5.3</version>
        <relativePath />
    </parent>

春云是

 <properties>
        <java.version>16</java.version>
        <spring-cloud.version>2020.0.3</spring-cloud.version>
    </properties>

春云已定

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

设置启动配置

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

在我设置的客户端的应用程序 yml 中

spring:
  profiles:
    active: @activatedProperties@
  application:
    name: @artifactId@
  config:
    import: "configserver:"
  cloud:
    config: 
      enabled: true
      uri: http://localhost:8086

@activatedProperties@ 是本地、开发、质量保证或产品。 问题是在这种情况下配置文件是本地的并且配置服务器是默认的吗?

【问题讨论】:

    标签: spring-cloud-config


    【解决方案1】:

    好的,我解决了这个问题。查看我的设置

    spring:
      profiles:
        active: @activatedProperties@
      application:
        name: @artifactId@
      config:
        import: "configserver:"
      cloud:
        config: 
          enabled: true
          uri: http://localhost:8086
    

    配置服务器会按如下方式处理

    http://localhost:8086/my-client/local
    

    my-client 是应用程序的名称,本地是配置文件。它需要映射到一个包含所有配置数据的 yml 文件'

    为此的 yml 文件将被称为 my-client-local.yml。我也会有 my-client-qa.yml, my-client-dev.yml, my-client-prod.yml 所以它会选择正确的配置文件

    【讨论】:

      猜你喜欢
      • 2015-07-13
      • 2022-11-06
      • 1970-01-01
      • 2023-02-15
      • 2016-11-26
      • 2022-12-04
      • 1970-01-01
      • 2016-03-21
      • 2018-10-10
      相关资源
      最近更新 更多