带有本地存储库的Spring Cloud Config Server配置

时间:2019-02-06 15:25:21

标签: spring spring-boot spring-cloud spring-cloud-config

我正在尝试使用后端存储库(文件系统)设置Spring Cloud Config Server,但是端点(http://localhost:8888/licensingservice/default)返回以下内容:

{"name":"licensingservice","profiles":["default"],"label":null,"version":null,"state":null,"propertySources":[]}

主要:

@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {

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

application.yml:

server:
   port: 8888
spring:
   profiles:
      active: native
    cloud:
       config:
          server:
             native:
                searchLocations: file:///Users/josedavi/Desenvolvimento/WorkSpace/Pessoal/sample-spring-microservices/sample-spring-microservices/config-server/src/main/resources/config

licenseservice.yml:

tracer.property: "I AM THE DEFAULT"
spring.jpa.database: "POSTGRESQL"
spring.datasource.platform: "postgres"
spring.jpa.show-sql: "true"
spring.database.driverClassName: "org.postgresql.Driver"
spring.datasource.url: "jdbc:postgresql://database:5432/eagle_eye_local"
spring.datasource.username: "postgres"
spring.datasource.password: "p0stgr@s"
spring.datasource.testWhileIdle: "true"
spring.datasource.validationQuery: "SELECT 1"
spring.jpa.properties.hibernate.dialect: "org.hibernate.dialect.PostgreSQLDialect"

enter image description here

服务配置的路径:

C:\Users\josedavi\Desenvolvimento\WorkSpace\Pessoal\sample-spring-microservices\sample-spring-microservices\config-server\src\main\resources\config

项目: https://github.com/jdavid-araujo/sample-spring-microservices

3 个答案:

答案 0 :(得分:1)

在您的application.yml配置服务中添加以下格式:

  

[classpath:/,classpath:/ config,classpath:/ config / {application},classpath:/ config / {application} / {profile}]

以上格式搜索位置分别来自config文件夹,下一个分别具有application名称,application名称和profile的文件夹。

spring:
   profiles:
      active: native
   cloud:
       config:
          server:
             native:
                searchLocations: "[classpath:/, classpath:/config, classpath:/config/{application}, classpath:/config/{application}/{profile}]"

答案 1 :(得分:1)

问题似乎出在您的searchLocations财产上。该路径必须到达licensingservice文件夹本身,并且如果服务器为多个服务提供配置,则必须为每个服务设置路径(以逗号分隔)。

尝试这种方式:

...
spring:
  ...
  cloud:
    config:
      server:
        native:
          searchLocations: file:///C:/Users/josedavi/Desenvolvimento/WorkSpace/Pessoal/sample-spring-microservices/sample-spring-microservices/config-server/src/main/resources/config/licensingservice

或者,您可以使用相对路径:

        ...
          searchLocations: classpath:config/licensingservice

此外,如果您正在阅读Spring Microservices in Action书(第3章),则可以看看source code example本身。

答案 2 :(得分:0)

config server folder structure

然后在 application.yaml 文件中 云: 配置: 服务器: 本国的: 搜索位置:“[classpath:/, classpath:/config, classpath:/config/{application}, classpath:/config/{application}/{profile}]”

它会完美运行