1 添加依赖
<dependencies>
<!--web-->
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
<!--config-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<!--eureka client-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
</dependency>
</dependencies>
2 添加配置
server:
port: 12000
eureka:
client:
service-url:
defaultZone: http://admin:1234@localhost:7001/eureka/
fetch-registry: true
register-with-eureka: true
spring:
application:
name: hello-config
cloud:
config:
server:
git:
uri: https://gitee.com/dp147258/hello-sc-2109a.git
search-paths: /**/config
label: master
3.添加启动类
@SpringBootApplication @EnableEurekaClient @EnableConfigServer
4.在provider(服务提供者添加依赖)
<!--config client-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
5.在provider(服务提供者)创建bootstrap.yml配置文件 删除appplication.yml里面配置(保留info跟logging日志)
bootstrap
server:
port: 9999
spring:
application:
name: hello-provider
jackson:
date-format: yyyy-MM-dd
time-zone: GMT+8
cloud:
config:
discovery:
enabled: true #开启配置服务发现
service-id: hello-config #配置中心服务名称
label: master #分支名称
profile: dev #环境名称
eureka:
client:
service-url:
defaultZone: http://admin:1234@localhost:7001/eureka/,http://admin:1234@localhost:7002/eureka/
register-with-eureka: true
fetch-registry: false
instance:
instance-id: ${spring.application.name}-${server.port}
prefer-ip-address: true
status-page-url-path: /actuator/info
health-check-url-path: /actuator/health
5.创建目录(方便区分)跟项目同名 gitBatch
创建文件夹config定义两个.yml文件(因在bootstrap跟application里面已无数据源)
在刚定义的.yml文件里面配置数据源
spring:
datasource:
username: root
password: 1234
url: jdbc:mysql:///db2109
创建文件 (方便上传)
在码云里面创建添加仓库(跟项目同名) ->开源
git init 初始化
git add . 添加暂存区
git commint . -m """" 提交到版本库
执行码云里面最后两行代码










