1、创建项目需要添加的依赖:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
2、yml文件配置:
server:
port: 8888
spring:
application:
name: cloud-server
cloud:
config:
server:
git:
uri: "git@gitlab.guangbao-uni.com:wangchaojie/SpringCloudConfig.git"
search-paths:respo
3、gitlab的ssh配置:
在~/.ssh目录下,生成公钥和密钥,将密钥设置到gitlab服务器,在config文件里设置一下内容,
Host gitlab.guangbao-uni.com
HostName gitlab.guangbao-uni.com
StrictHostKeyChecking no
Port 52381 #gitlab服务器端口号,不需要可以不写
User wangchaojie
IdentityFile ~/.ssh/id_rsa
具体参数根据实际情况修改
4、git上SpringCloudConfig项目中,在respo目录下有名为config-client-dev.properties的配置文件
4、在浏览器中访问:http://localhost:8888/config-client/dev,即可返回配置文件的信息