[英]Spring Cloud Config server - can't resolve from configuration repository
[英]Spring Cloud Config Server configuration with local repository
我正在尝试使用后端存储库(文件系统)设置 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);
}
}
应用程序.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
许可服务.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"
服务配置路径:
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
在配置服务的application.yml
中添加以下格式:
[类路径:/,类路径:/config,类路径:/config/{application},类路径:/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}]"
似乎问题出在您的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 章),您可以查看源代码示例本身。
然后在 application.yaml 文件 cloud: config: server: native: search-locations: "[classpath:/, classpath:/config, classpath:/config/{application}, classpath:/config/{application}/{profile} ]"
它将完美地工作
spring:
cloud:
config:
server:
native:
search-locations:
- classpath:/config # Config files for all microservices
- classpath:/config/{application} # Config files for specific applications
我建议您不要使用绝对路径,因为除非它在您的机器上运行,否则它将无法工作。 最好使用类路径的相对路径,以便您也可以在某处部署配置服务器。
native
配置文件该文档没有明确说明需要该配置文件,但对我来说,当我使用本native
配置文件时,它仅适用于多个search-locations
。
在属性(yml)文件中设置 uri,如下所示:
uri : file:///C:/properties/application.yml
spring:
application:
name: Config-Service
cloud:
config:
server:
git:
# uri: https://github.com/xxxx/config-server/
uri: file:///C:/properties/application.yml
clone-on-start: true
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.