Spring Cloud Config 服务端
cookqq ›博客列表 ›spring cloud

Spring Cloud Config 服务端

2018-09-06 17:18:20.0|分类: spring cloud|浏览量: 2643

摘要: 配置管理工具包,让你可以把配置放到远程服务器,集中化管理集群配置,目前支持本地存储、Git以及Subversion。

官网:http://cloud.spring.io/spring-cloud-config/

https://springcloud.cc/spring-cloud-config.html

http://cloud.spring.io/spring-cloud-static/spring-cloud-config/1.4.4.RELEASE/single/spring-cloud-config.html

这里写图片描述

注册码云账号https://gitee.com

创建项目,并且创建测试配置文件app.properties、app-dev.properties、app-test.properties

blob.png

spring cloud server项目结构

blob.png

ConfigServerApp.java

package com.cookqq.config.server;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;

/**
 * config server
 */
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApp 
{
    public static void main( String[] args )
    {
        SpringApplication.run(ConfigServerApp.class, args);
    }
}

application.yml

server:
  port: 8880
spring:
  application:
    name: config-server
  cloud:  
    config:
      server:
        git: 
          uri: https://gitee.com/bugeasy/spring-cloud-config
          username: xxx@qq.com
          password: xxxx
logging:
  level:
    org.springframework.cloud: DEBUG
    org.springframework.boot: DEBUG

pom.xml

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
  xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
  <modelVersion>4.0.0</modelVersion>

  <groupId>com.cookqq</groupId>
  <artifactId>config-server</artifactId>
  <version>0.0.1-SNAPSHOT</version>
  <packaging>jar</packaging>

  <name>config-server</name>
  <url>http://maven.apache.org</url>

  <properties>
    <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>

  <dependencies>
    <dependency>
    <groupId>org.apache.httpcomponents</groupId>
    <artifactId>httpclient</artifactId>
    <version>4.5.1</version>
</dependency>
    <dependency>
      <groupId>org.springframework.cloud</groupId>
      <artifactId>spring-cloud-config-server</artifactId>
    </dependency>
    <dependency>
      <groupId>junit</groupId>
      <artifactId>junit</artifactId>
      <version>3.8.1</version>
      <scope>test</scope>
    </dependency>
  </dependencies>
  
   <!-- 引入spring cloud的依赖 -->
  <dependencyManagement>
    <dependencies>
      <dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-dependencies</artifactId>
        <version>Edgware.RELEASE</version>
        <type>pom</type>
        <scope>import</scope>
      </dependency>
    </dependencies>
  </dependencyManagement>
  
  <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
                <executions>
                    <execution>
                        <goals>
                            <goal>repackage</goal>
                        </goals>
                    </execution>
                </executions>
            </plugin>
        </plugins>
    </build>

  
</project>

插件spring-boot-maven-plugin用于mvn install打包jar文件,如果不设置repackage,mvn install打包之后只有简单的代码,没有spring cloud的依赖代码

blob.png


ubuntu环境运行jar

blob.png

HTTP服务具有以下格式的资源:

/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties

{application}表示微服务的名称

{label}表示git仓库分支,默认是master


访问浏览器http://192.168.99.100:8880/app/dev

http://192.168.99.100:8880/app/dev/master


返回结果:

{
    "name":"app",
    "profiles":[
        "dev"
    ]
,
    "label":null,
    "version":"229d5fcd7a69ac583e0aab30202a7a4f504742ba",
    "state":null,
    "propertySources":[
        {
            "name":"https://gitee.com/bugeasy/spring-cloud-config/app-dev.properties",
            "source":{
                "profile":"dev-1.0"
            }

        }
,
        {
            "name":"https://gitee.com/bugeasy/spring-cloud-config/app.properties",
            "source":{
                "profile":"default-1.0"
            }

        }

    ]

}


http://192.168.99.100:8880/app-dev.properties

blob.png


一键分享文章

分类列表

  • • struts源码分析
  • • flink
  • • struts
  • • redis
  • • kafka
  • • ubuntu
  • • zookeeper
  • • hadoop
  • • activiti
  • • linux
  • • 成长
  • • NIO
  • • 关键词提取
  • • mysql
  • • android studio
  • • zabbix
  • • 云计算
  • • mahout
  • • jmeter
  • • hive
  • • ActiveMQ
  • • lucene
  • • MongoDB
  • • netty
  • • flume
  • • 我遇到的问题
  • • GRUB
  • • nginx
  • • 大家好的文章
  • • android
  • • tomcat
  • • Python
  • • luke
  • • android源码编译
  • • 安全
  • • MPAndroidChart
  • • swing
  • • POI
  • • powerdesigner
  • • jquery
  • • html
  • • java
  • • eclipse
  • • shell
  • • jvm
  • • highcharts
  • • 设计模式
  • • 列式数据库
  • • spring cloud
  • • docker+node.js+zookeeper构建微服务
版权所有 cookqq 感谢访问 支持开源 京ICP备15030920号
CopyRight 2015-2018 cookqq.com All Right Reserved.