我正在关注来自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;
}
}
答案 0 :(得分:2)
我认为客户端应用程序名称应与属性文件名称匹配。我不确定是否要求文件名与配置服务器中的properties / yml文件匹配。
客户端bootstrap.yml:
spring:
application:
name: config
cloud:
config:
uri:
- http://localhost:8888
application.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