使用SpringCloudConfig集中管理配置,将配置文件上传到码云(gitee.com),然后开始配置配置中心微服务。
新建微服务,导入maven依赖:
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
写配置文件:
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: https://gitee.com/username/config-server.git
server:
port: 8888
创建启动类:
@SpringBootApplication
@EnableConfigServer
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
启动服务并测试:http://localhost:8888/base-dev.yml
理论上应该是能看到配置文件的内容,但是却出现如下问题:
我的解决方式:
码云上复制URL不使用https,使用ssh方式
修改配置文件:
server:
port: 8888
spring:
application:
name: config-server
cloud:
config:
server:
git:
uri: git@gitee.com:username/config-server.git
ignore-local-ssh-settings: true
private-key: |
-----BEGIN RSA PRIVATE KEY-----
MIIEpAIBAAKCAQEA4+GMJe186iwLRjqUP/5KCCdi/jPO8sY3Oda7D3llIv8QHQ/3
jNaEexmmWUVQlgops2VFDAKHY1mlOeOUWjiqIdZUFDpeSVjsFTBnKe4pF/Bo6dfO
F/eEdg8ibnH89VNXebvmup1bBlpDIWWwINXIIg9jzC+LWjHaN6h4fYKFRpGYTy8F
ZUaSnhdOhmUjFk7EoDxNd5Ks9CGIC728sKl3y1MwXbIgI38B9f4QZQy215wb8UbE
K6vgNKIFQjHFCWPFC0OhZivMyLEyvp9EMZ42iX0FECpRQrcZhDbneQW4c1pD4CXT
TdNXbZj6gJhaqv3cRjKd73/CeCva7LfT3NbhjQIDAQABAoIBAQDeQxH/uDf66sSA
Vghctjgc5dWe3Ic/sWcSCcdfm2aykJZ10in/+wcyTd06+ulTvkvYBrEmupy0oS4P
XVJIATanVDWjmR53abyyGgi1E+6Ow9SAKBWCuM9AmxhZIuK3oPcT69pqL6olcwpA
277C9+CAoAQVllXTvgX5/V6wBArbvLR190eK2yzR+RiSOm7RYnvcTmTamvx5eSEK
cQyqqgx53UW4yRYwoCJEagS1BM3Neexe6+kH/0372a2mtaTVHxGZdk4WCdErzVBD
WP47o6f0w3kr2scSCwxl7LV7H2SShCpnMHQdhGzFT1xeYVLiV0gLfPCYkXWVWiz2
y9711gWhAoGBAPxaqzmF+LYENZRY4tBNzMO9igFL41H0nzB/lXxNwnnLnWEfSX2u
SEHV+RvVulbyvEnJp5VA9P9A9p3QFDJsuI9gedA9ejYBDqUf8VB6qxR4aZMqn/O9
AtTaM8UCmah5iNWXbFiRNheZvNSTkOaH6xoBeCAgGpK2HpXiIS9QMqnpAoGBAOcs
XWQUYf7xYdCwMcJ+bVtj3ObIEAnaIfHnW4Gfvx5PpFFO37KaWrs4iFAe56vtQPUa
P4iMQJ7uAgZmggzxpWVEjO+I+x93UFsAsgnqX6gaO8l2osOEU3R3nA7JdxK+XqhO
aHptstzj+KgYedmNMQz7SzzfN/RA2WynhNFXgxAFAoGANTvnPOY/Fh6DMv0hM7IF
zRDxyN46YPKKlk+DuEorCUhjtbZE6YdXZNP/jdijS24/PA2XFYwzYplQrO/VIuH+
ePhwGfauDjBg54J6hHCsIFBabRojzeYEb+Rr4VZwFbM1o2EjEPfpAkeDJxDOE2N+
u+itb5F2KZbTkui1+WYgmekCgYAHOVuxxPFLBkAIRXlImqrQME6254mYxThKVvCF
HHjceaCo6c4Txr8PGrUny89xj/h3sFpL6hYa4VUu3gUyYlrIz1uYIK+4TAI21c66
gJh8qFU19n8fnQL+oL4/uAwAifJrUAfzy3nLbVRX7GviYIcn4LJ5NICLIXup6ZI8
+H8gAQKBgQDn8O7AGo2UYI6E+KwfHGOcnoLgsXfis0zBV+XksqSSszumt0zwAkab
5iBIEkI27Wk+la2wqQqwcG07bOiB8bir1cVugXuWSs4zGbhqsrcBj39AT5gHWTfM
C09hN+Ugec4BmlvQPdQbAJogmwYnTXu7uxdmzD4/uww+irbwLS78UA==
-----END RSA PRIVATE KEY-----
将uri换成码云复制的ssh地址,增加ignore-local-ssh-settings: true和private-key,再次启动服务测试。结果如下:
private-key的获取:
进入Git的安装目录:E:\program files\develop\Git,打开git-bash.exe。
输入命令:ssh-keygen -t rsa -C "email@email.com","email@email.com"是你的github账号。
生成秘钥成功,打开C:\Users\jiang\.ssh,id_rsa文件中就是私钥。