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