搭建SpringCloud-Config-Server-码云云服务-Git分布式版本控制(一)

Spring Cloud Config

Spring Cloud Config为分布式系统中的外部化配置提供服务器和客户端支持。使用Config Server,您可以在所有环境中管理应用程序的外部属性。客户端和服务器映射的概念与Spring Environment和PropertySource抽象相同,因此它们与Spring应用程序非常契合,但可以与任何以任何语言运行的应用程序一起使用。随着应用程序通过从开发人员到测试和生产的部署流程,您可以管理这些环境之间的配置,并确定应用程序具有迁移时需要运行的一切。服务器存储后端的默认实现使用git,因此它轻松支持标签版本的配置环境,以及可以访问用于管理内容的各种工具。

首先创建config-learring文件夹,并在下面创建微服务项目microservice-config-server和pom.xml文件。

修改config-learring文件夹下的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>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.1.4.RELEASE</version>
		<relativePath/> <!-- lookup parent from repository -->
	</parent>
	
	<groupId>com.itmuch.cloud</groupId>
	<artifactId>microservice-spring-cloud</artifactId>
	<version>0.0.1-SNAPSHOT</version>
	<packaging>pom</packaging>
	
	<properties>
		<java.version>1.8</java.version>
	</properties>
	
  <modules>
  	<module>microservice-config-server</module>
  </modules>
  
  <dependencyManagement>
  	<dependencies>
		<dependency>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-dependencies</artifactId>
			<version>2.1.4.RELEASE</version>
			<type>pom</type>
			<scope>import</scope>
		</dependency>
		<!--Greenwich.RELEASE-->
		<dependency>
		    <groupId>org.springframework.cloud</groupId>
		    <artifactId>spring-cloud-dependencies</artifactId>
		    <version>Greenwich.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>
		</plugin>
	</plugins>
  </build>
</project>

在Eclipse中导入微服务项目microservice-config-server

修改微服务中的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.itmuch.cloud</groupId>
		<artifactId>microservice-spring-cloud</artifactId>
		<version>0.0.1-SNAPSHOT</version>
	</parent>
	
	<artifactId>microservice-config-server</artifactId>
    <packaging>jar</packaging>

	<properties>
		<java.version>1.8</java.version>
	</properties>

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

</project>

 在启动类中加入注解@EnableConfigServer:

@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {

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

}

码云

码云是开源中国社区2013年推出的基于 Git 的完全免费的代码托管服务,这个服务是基于 Gitlab 开源软件所开发的,我们在 Gitlab 的基础上做了大量的改进和定制开发,目前已经成为国内最大的代码托管系统,致力于为国内开发者提供优质稳定的托管服务。

码云主要功能

码云除了提供最基础的 Git 代码托管之外,还提供代码在线查看、历史版本查看、Fork、Pull Request、打包下载任意版本、Issue、Wiki 、保护分支、代码质量检测、PaaS项目演示等方便管理、开发、协作、共享的功能。

登录码云官网,注册登录后在我的码云中创建个人仓库

然后点击克隆/下载复制GIT地址 

安装Git

Git(读音为/gɪt/。)是一个开源的分布式版本控制系统,可以有效、高速地处理从很小到非常大的项目版本管理。 Git是为了帮助管理 Linux 内核开发而开发的一个开放源码的版本控制软件,下载地址在官网找即可,安装过程很简单一直下一步就能完成。

 

配置环境变量在系统变量Path中加入 F:\java\Git\bin(根据自己安装git的路径)

Win+R打开CMD之后,输入git命令后,控制台输出信息git已成功安装。

安装tortoise git

TortoiseGit是一个开放的git版本控制系统的源客户端,只运行于Windows系统中,与操作系统紧密结合,使用起来非常方便。如果有TortoiseSVN的使用经验,则使用TortoiseGit很容易上手。

安装也很简单下一步就行,安装成功后用在码云复制的git地址下载仓库中的资源文件。

在刚下载的仓库文件中创建application.yml内容为:

profile: profile-default

然后提交同步到仓库中去,修改微服务中的application.yml文件内容:

server:
  port: 8080
spring:
  cloud:
    config:
      server:
        git:
          uri: https://gitee.com/guigui2019/guiguick

启动项目后,在浏览器中输入请求地址,显示结果如图:

新建test.yml并上传提交

profile: test-dev

在浏览器中输入请求地址,显示结果如图:

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值