spring cloud config使用svn作为仓库

springcloud config 默认是使用git,但是比较多的公司还是使用svn。这里我使用svn来作为仓库来配置config server .

config server

pom.xml文件

<dependencies>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-config-server</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.cloud</groupId>
            <artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.tmatesoft.svnkit</groupId>
            <artifactId>svnkit</artifactId>
        </dependency>
    </dependencies>

说明:spring-boot-starter-actuator这个是监控用的,svnkit是config 使用svn仓库需要用到的jar包。

application.yml文件

spring:
  cloud:
    config:
      server:
        svn:
          uri: https://ip/svn/cloudConfig/
          username: youUserName
          password: youPassword
        default-label: config
  profiles:
    active: subversion
  application:
    name: spring-cloud-config-server

说明:
url对应你的svn地址,default-label默认访问的是trunk,config使用svn就必须加上spring.profiles.active =subversion

Application.class 类
在启动类上加上@EnableConfigServer注解。

@EnableConfigServer
@SpringBootApplication
@EnableEurekaClient
public class ConfigdemoApplication {

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

启动config server ,在浏览器上输入http://localhost:10066/test.yml 后会出现test.yml的内容就表示启动成功。
这里的test.yml是存在svn的cloudConfig仓库下的config文件夹。

config client

这里有个小坑:
只要Spring Boot Actuator和Spring Config Client在类路径上,任何Spring Boot应用程序都会尝试联系配置服务器http://localhost:8888,默认值为 spring.cloud.config.uri。如果你想改变这个默认,你可以设置spring.cloud.config.uri在bootstrap.[yml | properties] 或通过系统属性或环境变量。
如果你的client的 yml文件为application的话他会默认去本地查找http://localhost:8888的config server.
pom.xml

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

bootstrap.yml

spring:
  cloud:
    config:
      uri: http://localhost:10066
      profile: dev
  application:
    name: test

启动client,检验是否成功。

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值