此项目为了统一管理项目的配置文件,将配置文件放到远程仓库,所有的项目都可以使用,统一改动,方便。
还是基于EurekaServer的。
1.启动 https://blog.csdn.net/qq_33371766/article/details/101622727 这里面的EurekaServer服务端。
2.创建springboot项目。
3.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>
<groupId>com.didispace</groupId>
<artifactId>config-server</artifactId>
<version>1.0.0</version>
<packaging>jar</packaging>
<name>config-server</name>
<description>Spring Cloud project</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.3.5.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<java.version>1.8</java.version>
</properties>
<dependencies>
<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-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Brixton.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>
4.application.properties
spring.application.name=config-server
server.port=7001
eureka.client.serviceUrl.defaultZone=http://localhost:1111/eureka/
# git管理配置
# git仓库地址 这里是码云的仓库地址,注意需要创建公开的仓库
spring.cloud.config.server.git.uri=https://gitee.com/****/SpringCloudLearnRepo.git
# 配置文件所在的文件夹
spring.cloud.config.server.git.searchPaths=config-repo
spring.cloud.config.server.git.username= 这里填写自己的仓库的账号
spring.cloud.config.server.git.password= 这里填写自己的仓库的密码
#spring.cloud.config.server.git.username=username
#spring.cloud.config.server.git.password=password
spring.cloud.config.server.git.default-label=master
# 开启本地配置
#spring.profiles.active=native
5.启动类
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.client.discovery.EnableDiscoveryClient;
import org.springframework.cloud.config.server.EnableConfigServer;
@EnableConfigServer
@EnableDiscoveryClient
@SpringBootApplication
public class Application {
public static void main(String[] args) {
new SpringApplicationBuilder(Application.class).web(true).run(args);
}
}
至此config-server配置完成启动成功。