springCloud分布式配置中心-本地文件篇

前言
分布式配置中心的话,我们这一片介绍的是使用本地配置文件进行编程,详细信息如下(版本是springCloud 2.0 + )

  1. configServer
    pom.xml配置:
<parent>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-parent</artifactId>
		<version>2.0.1.RELEASE</version>
	</parent>
	<!-- 管理依赖 -->
	<dependencyManagement>
		<dependencies>
			<dependency>
				<groupId>org.springframework.cloud</groupId>
				<artifactId>spring-cloud-dependencies</artifactId>
				<version>Finchley.M7</version>
				<type>pom</type>
				<scope>import</scope>
			</dependency>
		</dependencies>
	</dependencyManagement>
	<dependencies>
		<!--spring-cloud 整合 config-server -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-config-server</artifactId>
		</dependency>
		<!-- SpringBoot整合eureka客户端 -->
		<dependency>
			<groupId>org.springframework.cloud</groupId>
			<artifactId>spring-cloud-starter-netflix-eureka-client</artifactId>
		</dependency>
	</dependencies>
	<!-- 注意: 这里必须要添加, 否者各种依赖有问题 -->
	<repositories>
		<repository>
			<id>spring-milestones</id>
			<name>Spring Milestones</name>
			<url>https://repo.spring.io/libs-milestone</url>
			<snapshots>
				<enabled>false</enabled>
			</snapshots>
		</repository>
	</repositories>
	<!-- 将文件打成可执行的jar包 -->
<build>
		<finalName>${project.artifactId}</finalName><!--打jar包去掉版本号-->
		<plugins>
			<plugin>
				<groupId>org.springframework.boot</groupId>
				<artifactId>spring-boot-maven-plugin</artifactId>
			</plugin>
		</plugins>
	</build>

application.yml

####端口号      
server:
  port: 8888

###服务注册到eureka地址
eureka:
  client:
    service-url:
           defaultZone: http://localhost:8100/eureka
spring:
  application:
    ####注册中心应用名称
    name: config-server 
  profiles:
  ###配置文件的环境,native ,或者git
    active: native
  cloud:
    config:
      server:
        native:
          search-locations: classpath:/shared/{profile}
        git:
          uri: https://gitee.com/zhang.w/cloud-service-configs.git
          default-label: master
          force-pull: true
          searchPaths: '{profile}'
  1. 上面的配置文件中的profile,是在对应的工程里面的配置文件存在的,
    在这里插入图片描述

猜你喜欢

转载自blog.csdn.net/weixin_41509621/article/details/88385721