0

我正在关注 spring.io 中的 Spring 云配置示例。尝试使用 git 从属性文件中读取属性。我尝试了 Stackoverflow 中针对类似问题给出的建议,但没有奏效。有什么见解可以帮助解决这个问题吗?

顺便说一句,我使用的是 Windows 10、JDK 8、Spring Boot 2.0.4

这是我在服务器端的配置。我尝试了 git 和 native 但没有运气:

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"

配置客户端配置:

    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;
        }
    }
4

1 回答 1

2

我认为客户端应用程序名称应该与属性文件名匹配。我不确定这是否要求文件名与配置服务器中的属性/yml 文件匹配。

客户端 bootstrap.yml:

spring:
  application:
    name: config

  cloud:
    config:
      uri:
      - http://localhost:8888

应用程序.yml:

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

配置服务器 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       
于 2018-08-06T20:55:34.653 回答