- 在码云上申请账户(略)
- 在码云上创建个仓库config-repo,在创建个文件夹spring-cloud-config-demo
分别创建application-dev.properties\application-pro.properties\application-test.properties 文件
application-dev.properties
server.port=8901
version = dev-3.0.0
application-pro.properties
server.port=8901
version = pro-3.0.0
application-test.properties
server.port=8901
version = test-3.0.0
如图目录结构如下:
- 创建spring-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 https://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.7.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.fengrz.demo</groupId>
<artifactId>spring-config-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>spring-config-server</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.version>
<spring-cloud.version>Greenwich.SR2</spring-cloud.version>
</properties>
<dependencies>
<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>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>${spring-cloud.version}</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
<executions>
<execution>
<goals>
<goal>repackage</goal>
</goals>
</execution>
</executions>
</plugin>
</plugins>
</build>
</project>
- application.properties
server.port=8900
spring.cloud.config.server.git.uri=https://gitee.com/fengrz/config-repo.git
spring.cloud.config.server.git.searchPaths= spring-cloud-config-demo
#spring.cloud.config.server.git.username=
#spring.cloud.config.server.git.password=
- SpringConfigServerApplication.java
package com.fengrz.demo.springconfigserver;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@SpringBootApplication
@EnableConfigServer
public class SpringConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(SpringConfigServerApplication.class, args);
}
}
- 运行SpringConfigServerApplication,main方法
- 浏览器访问
第一种:
http://localhost:8900/application-test.properties
http://localhost:8900/application-pro.properties
http://localhost:8900/application-dev.properties
第二种:
http://localhost:8900/application/dev
http://localhost:8900/application/test
http://localhost:8900/application/pro
9.
10.
11.
12. List item