SpringCloud第九篇 Config配置中心-Config Server(GIT)

1.新建一个项目config-server

2.pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<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>com.star.guo</groupId>
        <artifactId>stage4</artifactId>
        <version>0.0.1-SNAPSHOT</version>
    </parent>
    <!-- <groupId>com.star.guo</groupId> -->
    <artifactId>config-server</artifactId>
    <!-- <version>0.0.1-SNAPSHOT</version> -->
    <name>config-server</name>
    <description>Demo project for Spring Boot</description>


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

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

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


</project>
3.添加注解

package com.star.guo;

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

@SpringBootApplication
@EnableConfigServer
@EnableEurekaClient
public class ConfigServerApplication {

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

}

4添加和修改配置文件application.yml

       
server:
  port: 8008
eureka: 
  client:
    serviceUrl:
      defaultZone: http://localhost:8000/eureka/
spring: 
  application:  
    name: config-server
  cloud:  
    config: 
      server: 
        git:
#git地址
          uri: https://github.com/guoxingege/remote_config
#查找的路径
          search-paths: properties

#          default-label: master
#账号 git仓库为public,读取不需要账号密码
          username: 
#密码
          password: 
          default-label: master
          
#对应的branch
      label: master
#/{application}/{profile}[/{label}]
#/{application}-{profile}.yml
#/{application}-{profile}.properties
#/{label}/{application}-{profile}.yml 
#/{label}/{application}-{profile}.properties
#[label]是可以省略的,默认label是master分支

5.启动

先启动eureka再启动config-server

6.访问测试

访问http://localhost:8008/starguo/dev

会显示{"name":"starguo","profiles":["dev"],"label":null,"version":"1fefe71801d400e9f8fdf59db5e821f94e4055e2","state":null,"propertySources":[]}

*如果使用自己的git地址,记得把配置文件放上去就行

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值