Search code examples
spring-cloud-config

spring cloud config client does not load config files. Think the problem may be profile settins


I have looked at past stack traces and I have all the correct settings. I think this is more a problem of the profile.

I am not using git as a data source but instead using S3 but it works, On my local when I run

http://localhost:8086/application/default

it returns

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

on my pom I have set for spring boot

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

Spring cloud is

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

Spring cloud is set

    <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>

Set starter config

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

in the application yml for the client I have set

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

@activatedProperties@ is either local, dev, qa, or prod. Is the problem the fact that profile in this case is local and the config server is expecting default.


Solution

  • Ok I fixed the problem. Looking at my settings

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

    Config server will process it as follows

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

    my-client being the name of the application local being the profile. It needs to map to a yml file with all the config data on'

    The yml file for this will be called my-client-local.yml. I will also have have my-client-qa.yml, my-client-dev.yml, my-client-prod.yml so it picks up the right profile