spring-cloud===>config配置中心
2020-09-06 本文已影响0人
MaJiT
准备工作
- git上上传通用的配置文件
1.创建配置中心微服务

2.导入依赖
<!-- config-server -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
3.配置文件
#服务端口号
server:
port: 3344
spring:
#服务名称
application:
name: cloud-config-service
cloud:
config:
server:
git:
uri: https://gitee.com/majit/spring-cloud-config.git
username: xxxx@qq.com
password: xxxx
search-paths: spring-cloud-config
label: master
#服务注册
eureka:
client:
service-url:
defaultZone: http://localhost:7001/eureka,http://localhost:7002/eureka
#将自己注册到Eureka中
register-with-eureka: false
#是否从Eureka中获取到自己的信息
fetch-registry: true
instance:
instance-id: config-service #注册的状态名
prefer-ip-address: true #访问路径可以显示IP地址
4.启动类添加@EnableConfigServer注解
@SpringBootApplication
@EnableConfigServer
public class ConfigApplication3344 {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication3344.class,args);
}
}
5.测试
http://localhost:3344/master/application-dev.yml