springcloud 配置中心
一、服务端配置如下
- pom文件添加spring-cloud-config-server依赖。
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
- 在主启动类上添加@EnableConfigServer注解,同时增加@EnableDiscoveryClient注解,注明自己本身也是要被注册到注册中心的。
- bootstrap.yml中填写配置信息(当前配置为项目本身的文件位置),可以配置为本地文件的位置,也可配置到git上进行托管,注释部分为配置到本地和git上。
spring:
application:
name: config-center
profiles:
active: native
cloud:
config:
server:
native:
searchLocations: classpath:/configs/{profile}
# searchLocations: file:/d:/configs/{profile}
# git:
# uri: https://gitee.com/xxx/cloud-center-configs.git
# default-label: master
# force-pull: true
# searchPaths: '{profile}'
二、客户端配置
- 添加 bootstrap.yml配置信息,在oauth-center微服务中添加了config-center,profile统一设置的是dev模式,如果想实现test、prod、dev三种模式,可在config-center中进行配置,然后profile设置为需要的环境即可。
spring:
application:
name: oauth-center
cloud:
config:
discovery:
enabled: true
serviceId: config-center
profile: dev
fail-fast: true
- 启动类上不用作修改。