springcloud費話之配置中心基礎(SVN)

目錄:html

springcloud費話之Eureka基礎java

springcloud費話之Eureka集羣git

springcloud費話之Eureka服務訪問(restTemplate)spring

springcloud費話之Eureka接口調用(feign)apache

springcloud費話之斷路器(hystrix in feign)bootstrap

springcloud費話之配置中心基礎(SVN)app

springcloud費話之配置中心客戶端(SVN)maven

 

在集羣運行的過程當中,難以對總體的配置進行修改svn

 

因此集羣的配置修改,在統一的位置中進行修改是廣泛手段spring-boot

 

在springcloud中,使用配置中心進行管理

 

1、配置

 

1.獲取pom

 

 

使用svn的方式,還須要svnkit的pom

 

完整pom代碼以下

 

<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>

    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.1.7.RELEASE</version>
        <relativePath /> <!-- lookup parent from repository -->
    </parent>

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

    <name>lyh-config</name>

    <properties>
        <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
        <java.version>1.8</java.version>
        <!-- SR2會報錯,未解決 -->
        <spring-cloud.version>Greenwich.SR1</spring-cloud.version>
    </properties>

    <dependencyManagement>
        <dependencies>
            <dependency>
                <groupId>org.springframework.cloud</groupId>
                <artifactId>spring-cloud-dependencies</artifactId>
                <version>${spring-cloud.version}</version>
                <type>pom</type>
                <scope>import</scope>
            </dependency>
        </dependencies>
    </dependencyManagement>

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

        <!-- svn的客戶端lib -->
        <dependency>
            <groupId>org.tmatesoft.svnkit</groupId>
            <artifactId>svnkit</artifactId>
        </dependency>
    </dependencies>

    <build>
        <plugins>
            <plugin>
                <groupId>org.springframework.boot</groupId>
                <artifactId>spring-boot-maven-plugin</artifactId>
            </plugin>
        </plugins>
    </build>
</project>

 

2.建立maven項目並引入pom

  略

 

3.配置svn地址相關

 

yarm的配置,文件名爲bootstrap.yml,而並不是application.yml

 

server:
  port: 9000
spring:
  application:
    name: config-server
  profiles:#必須指定爲svn,不然默認訪問git
    active: subversion
  cloud:
    config:
      server:
        svn:
          uri: https://47.105.121.158/svn/liuyuhang_FM/configCenter/#svn要訪問的最終文件夾地址
          username: liuyuhang
          password: *********
          search-paths: #這一項應該有,允空
          default-label: testConfig
      basedir: /data #臨時文件夾,防清空

 

svn的update地址,對應關係以下:

 

包含文件以下:

 

 2、建立啓動類

 

1.建立啓動類並添加註解@EnableConfigServer,代碼以下:

 

package com.lyh.lyh_eureka_server;

import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.config.server.EnableConfigServer;
import org.springframework.cloud.netflix.eureka.EnableEurekaClient;
import org.springframework.cloud.netflix.hystrix.EnableHystrix;
import org.springframework.cloud.openfeign.EnableFeignClients;

@SpringBootApplication
@EnableConfigServer
public class ConfigRun {

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

}

 

三.測試

 

注意訪問地址和svn配置相關的對應關係

 

訪問地址,dev下地址和結果

 訪問具體文件的地址和結果

 

以上!

相關文章
相關標籤/搜索