1. 建立空的子项目 springcloud-config-server
2. 修改 pom.xml
增加:
<!-- 以下是增加的 -->
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<!-- 以上是增加的 -->
修改后的 pom.xml 如下
<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.xnx3.springcloud</groupId>
<artifactId>springcloud-main</artifactId>
<version>1.0-SNAPSHOT</version>
</parent>
<groupId>com.xnx3.springcloud.config.server</groupId>
<artifactId>springcloud-config-server</artifactId>
<!-- 以下是增加的 -->
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-actuator</artifactId>
</dependency>
</dependencies>
<build>
<plugins>
<plugin>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-maven-plugin</artifactId>
</plugin>
</plugins>
</build>
<!-- 以上是增加的 -->
</project>
3. 添加启动类 com.xnx3.springcloud.config.ConfigServerApplication
package com.xnx3.springcloud.config;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
4. 添加配置文件 application.properties
server.port=8083
#配置文件所在的git
spring.cloud.config.server.git.uri=https://gitee.com/mail_osc/springcloud_learn.git
#配置文件所在目录
spring.cloud.config.server.git.uri=search-paths:cloud-config-repo
5. 启动
。。。