spring:
application:
name: microservice-config-server
cloud:
config:
server:
git:
uri: https://git.oschina.net/itmuch/spring-cloud-config-repo # 配置Git仓库的地址
username: # Git仓库的账号
password: # Git仓库的密码
支持占位符 {application} {profile} {label}
spring:
application:
name: microservice-config-server
cloud:
config:
server:
git:
uri: https://git.oschina.net/itmuch/{application}
username: # Git仓库的账号
password: # Git仓库的密码
logging:
level:
org.springframework.cloud: DEBUG
org.springframework.boot: DEBUG
## 测试:可以使用http://localhost:8080/spring-cloud-config-repo-default.yml 获取到http://localhost:8080/spring-cloud-config-repo下的application.properties
模式匹配
spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
repos:
simple: https://github.com/simple/config-repo
special:
pattern: special*/dev*,*special*/dev*
uri: https://github.com/special/config-repo
local:
pattern: local*
uri: file:/home/configsvc/config-repo
# 测试:
# 使用http://localhost:8080/foo-default.yml,可以访问到https://github.com/spring-cloud-samples/config-repo
# 使用http://localhost:8080/special/dev,观察日志及返回结果
搜索目录
foo,bar* 都会查询
spring:
cloud:
config:
server:
git:
uri: http://git.oschina.net/itmuch/spring-cloud-config-repo
search-paths: foo,bar*
logging:
level:
org.springframework.cloud: DEBUG
org.springframework.boot: DEBUG
# 测试:访问http://localhost:8080/application/default
启动的时候,就加载配置文件
启动时快速识别错误的配置源
spring:
cloud:
config:
server:
git:
uri: https://github.com/spring-cloud-samples/config-repo
repos:
team-a:
pattern: microservice-*
clone-on-start: true
uri: http://git.oschina.net/itmuch/spring-cloud-config-repo
logging:
level:
org.springframework.cloud: DEBUG
org.springframework.boot: DEBUG
# 测试:
# 1.观察启动日志
# 2.访问http://localhost:8080/microservice-foo/dev
全局配置启动时加载配置文件:
spring:
cloud:
config:
server:
git:
clone-on-start: true
/health
{profile} 是 default, {label} 是 master
spring:
application:
name: microservice-config-server
cloud:
config:
server:
git:
uri: https://git.oschina.net/itmuch/spring-cloud-config-repo/ # 配置Git仓库的地址
username: # Git仓库的账号
password: # Git仓库的密码
health:
repositories:
a-foo:
label: config-label-v2.0
name: microservice-foo
profiles: dev
http://localhost:8080/health
{
"status": "UP"
}
然鹅 ,并不能用。
config server 依赖的加密是: jce
bootstrap.yml
encrypt:
key: foo # 设置对称密钥
http://localhost:8080/encrypt -d mysecret
http://localhost:8080/decrypt -d 密文解密
encryption.yml
spring:
datasource:
username: dbuser
password: '{cipher}851a6effab6619f43157a714061f4602be0131b73b56b0451a7e268c880daea3'
如果用properties,则’{cipher}'不能使用单引号
http://localhost:8080/encryption-default.yml
profile: default
spring:
datasource:
password: mysecret
username: dbuser
test: '1'
直接返回密文本身:
spring:
application:
name: microservice-config-server
cloud:
config:
server:
git:
uri: https://git.oschina.net/itmuch/spring-cloud-config-repo # 配置Git仓库的地址
username: # Git仓库的账号
password: # Git仓库的密码
encrypt:
enabled: false
测试结果失败:
profile: default
spring:
datasource:
password: mysecret
username: dbuser
test: '1'
生成秘钥对:
keytool -genkeypair -alias mytestkey -keyalg RSA -dname "CN=Web Server,OU=Unit,O=Organization,L=City,S=State,C=US" -keypass changeme -keystore serverhua.jks -storepass letmein
bootstrap.yml
encrypt:
keyStore:
location: classpath:/server.jks # jks文件的路径
password: letmein # storepass
alias: mytestkey # alias
secret: changeme # keypass
尝试加密
curl http://localhost:8080/encrypt -d mysecret