spring clound 之 springcloud config 入门

 Spring Cloud Config 的作用是统一配置 管理,只要服务器端更新各客户端就可以更新。


一个最简单的spring clound config 入门配置 例子

服务端model  配置 :

1、pom.xml




    4.0.0

    com.peidw
    sc-config-server
    1.0-SNAPSHOT
    
        org.springframework.boot
        spring-boot-starter-parent
        1.2.8.RELEASE
         
    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                Angel.SR6
                pom
                import
            
        
    

    
        
            org.springframework.cloud
            spring-cloud-starter-config
        

        
        
            org.springframework.boot
            spring-boot-starter-web
        

        
        
            org.springframework.boot
            spring-boot-starter-actuator
        

        
            org.springframework.cloud
            spring-cloud-config-server
        


        
            com.fasterxml.jackson.core
            jackson-core
            2.8.3
        

        
            com.fasterxml.jackson.core
            jackson-databind
            2.8.3
        
        
            com.fasterxml.jackson.core
            jackson-annotations
            2.8.3
        


    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    



2、application.properties

server.port=8888

3、bootstrap.properties  指定配置 的地址

spring.cloud.config.server.git.uri: https://github.com/peidw/sctest


4、启动类


package com.peidw.scconfig;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by peidw on 2016/10/10.
 */
@Configuration
@EnableAutoConfiguration
@RestController
@EnableConfigServer
public class Application {

    public static void main(String[] args ){
        SpringApplication.run(Application.class, args);
    }

}

客服model  配置 :

1、pom.xml



    4.0.0

    com.peidw
    sc-config-client
    1.0-SNAPSHOT
    
        org.springframework.boot
        spring-boot-starter-parent
        1.2.8.RELEASE
         
    

    
        
            
                org.springframework.cloud
                spring-cloud-dependencies
                Angel.SR6
                pom
                import
            
        
    

    
        
            org.springframework.boot
            spring-boot-starter-web
        
        
            org.springframework.cloud
            spring-cloud-config-client
        
        
            org.springframework.boot
            spring-boot-starter-actuator
        

        
            org.springframework.boot
            spring-boot-starter-test
            test
        

        
            com.fasterxml.jackson.core
            jackson-core
            2.8.3
        

        
            com.fasterxml.jackson.core
            jackson-databind
            2.8.3
        
        
            com.fasterxml.jackson.core
            jackson-annotations
            2.8.3
        


    

    
        
            
                org.springframework.boot
                spring-boot-maven-plugin
            
        
    




2、application.properties

server.port=8881
3、 bootstrap.properties

spring.application.name:foo
spring.cloud.config.env:default
spring.cloud.config.label:master
spring.cloud.config.uri:http://127.0.0.1:8888

云配置 文件指 “服务端model”


4、启动类

package com.peidw.scconfigclient;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 * Created by peidw on 2016/10/10.
 */
@SpringBootApplication
@RestController
public class Application {
    @Value("${name:World!}")
    String bar;

    @RequestMapping("/")
    String hello() {
        return "Hello " + bar + "!";
    }

    public static void main(String[] args) {
        SpringApplication.run(Application.class, args);
    }
}



测试验证:

spring clound 之 springcloud config 入门_第1张图片


原理不详说,用起来确实确方便,具体可以参考:

http://blog.csdn.net/liaokailin/article/details/51307215



你可能感兴趣的:(spring,cloud)