Spring Cloud Config Server configuration with local repository

邮差的信 提交于 2019-12-11 17:21:38

问题


I'm trying to set up Spring Cloud Config Server with backend repository (filesystem), but the endpoint(http://localhost:8888/licensingservice/default) returns the following:

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

The Main:

@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {

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

The 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

The licensingservice.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"

The path of the service config:

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

The Project: https://github.com/jdavid-araujo/sample-spring-microservices


回答1:


Add the following format in your application.yml of config service:

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

The above format search locations from config folder, next folder with application name, application name and profile respectively.

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



回答2:


It seems that the problem is your searchLocations property. The path must reach the licensingservice folder itself, and if the server provides configuration for more than one service, you must set the paths for each of them (separated by comma).

Try this way:

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

Alternatively, you can use the relative path:

        ...
          searchLocations: classpath:config/licensingservice

Also, if you are reading the Spring Microservices in Action book (Chapter 3), you can take a look at the source code example itself.



来源:https://stackoverflow.com/questions/54557032/spring-cloud-config-server-configuration-with-local-repository

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!