spring cloud放弃系列之--1-config

来源:互联网 发布:盛势网络剧日常花絮 编辑:程序博客网 时间:2024/05/22 04:51

是什么

Spring Cloud Config为分布式系统中的外部化配置提供服务器和客户端支持。使用Config Server,您可以集中管理所有环境中应用程序的外部属性

干嘛用

统一管理各个微服务的配置文件

怎么用

引入jar

    <dependencies>        <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-config-server</artifactId>        </dependency>    </dependencies>

在程序的入口Application类加上@EnableConfigServer注解开启配置服务器。

@SpringBootApplication@EnableConfigServerpublic class ConfigServiceApplication {    public static void main(String[] args) {        SpringApplication.run(ConfigServiceApplication.class, args);    }}

application.yml 配置

server:  port: 7000spring:  application:    name: config-servie  cloud:    config:      server:        git:          uri: https://git.oschina.net/jamen/blife-config-centor.git          search-paths: blife-config-centor

在git中放 yml文件

config-test-dev.yml

spring:  application:    name: config-test

启动config-service

请求http://10.10.8.101:7000/config-test/dev返回{"name":"config-test","profiles":["dev"],"label":null,"version":null,"state":null,"propertySources":[{"name":"https://git.oschina.net/jamen/blife-config-centor.git/config-test-dev.yml","source":{"spring.application.name":"config-test"}}]}

Dockerfile

FROM frolvlad/alpine-oraclejdk8:slimVOLUME /tmpADD config-service-1.0-SNAPSHOT.jar app.jarRUN sh -c 'touch /app.jar'ENV JAVA_OPTS=""ENTRYPOINT [ "sh", "-c", "java $JAVA_OPTS -Djava.security.egd=file:/dev/./urandom -jar /app.jar" ]EXPOSE 7000

config 客户端的使用

引入jar

        <dependency>            <groupId>org.springframework.cloud</groupId>            <artifactId>spring-cloud-starter-config</artifactId>        </dependency>

boostrapt.yml

spring:  cloud:    config:      allow-override: false      #label: master      profile: dev      uri: http://10.10.8.101:7000 #配置中心地址
0 0