gitspring-bootspring-cloudconfigserver

Problems reading configuation using Spring cloud config with GIT


I am following the Spring cloud config sample from spring.io. Trying to read a property from properties file by using git. I tried the suggestions given in Stackoverflow for similar questions but it did not work. Any insights to help solve this issue?

BTW, I am using Windows 10, JDK 8, Spring Boot 2.0.4

This is my config in server side. I tried with both git and native but no luck:

spring:
  profiles:
    active:
    # - native
    - development

---
spring:
  profiles: native
  cloud:
    config:
      server:
        native:
          search-locations:
          - C:/config-repo
--- 

spring:        
  profiles: development

# using git  

  cloud:
    config:
      server:
        git:
          uri: file:///C:/config-repo

---

server:
  port: 8888   

config.properties file exists in C:\config-repo
 contents of config.properties:

        message = "Hello Spring Boot config"

Config Client configuration:

    public class SpringCloudconfigClientApplication {

        public static void main(String[] args) {
            SpringApplication.run(SpringCloudconfigClientApplication.class, args);
        }
    }

    @RefreshScope
    @RestController
    class MessageRestController {

        @Value("${message:Hello default}")
        private String message;

        @RequestMapping("/message")
        String getMessage() {
            return this.message;
        }
    }

Solution

  • I figured the client application name should match the properties file name. I am not sure if this is a requirement to have the file name matching with properties/yml file in config server.

    Client side bootstrap.yml:

    spring:
      application:
        name: config
    
      cloud:
        config:
          uri:
          - http://localhost:8888
    

    application.yml:

    management:
      endpoints: 
        web: 
          exposure: 
            include:
            - '*'
    

    Config Server application.yml:

    spring:
      profiles:
        active:
        # - native
        # - development
        - remote_repo
    
    ---
    spring:
      profiles: native
      cloud:
        config:
          server:
            native:
              search-locations:
              - C:/config-repo
    --- 
    
    spring:        
      profiles: development
    
    # using git/local file system 
    
      cloud:
        config:
          server:
            git:
              uri: file:///C:/config-repo
    
    ---
    
    spring:        
      profiles: remote_repo
    
    # using git/local file system 
    
      cloud:
        config:
          server:
            git:
              uri: https://github.com/<<YOUR_USER_NAME>>/cloud-config-repo
              skip-ssl-validation: true
              username: <<YOUR_USER_NAME>>
              password: <<YOUR_REPO_PASSWORD>>
    
    ---
    
    server:
      port: 8888