SpringCloud-config(git+码云)
新建一个工程 config-server
1、启动类:ConfigServerApplication
package com.cloud.config;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.boot.builder.SpringApplicationBuilder;
import org.springframework.cloud.config.server.EnableConfigServer;
@EnableConfigServer
@SpringBootApplication
public class ConfigServerApplication {
public static void main(String[] args) {
new SpringApplicationBuilder(ConfigServerApplication.class)
.web(true).run(args);
}
}
2、配置文件:application.properties
spring.application.name=config-server
server.port=7001
spring.cloud.config.server.git.uri=https://gitee.com/xxxx/spring-cloud.git
spring.cloud.config.server.git.search-paths=spring_cloud_in_action/config-repo
spring.cloud.config.name=11xxxx36@qq.com
spring.cloud.config.password=xxxx
uri:这里配置的是码云仓库地址
paths:是该地址下的文件夹
name:用户名
password:密码
3、给码云上传配置文件
利用git工具给仓库https://gitee.com/xxxx/spring-cloud.git/spring_cloud_in_action/config-repo/下上传配置文件
didispace-dev.properties
didispace.properties
这里我上传了两个文件
4、pom文件
<?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>1.5.3.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<groupId>com.cloud</groupId>
<artifactId>config-server</artifactId>
<version>0.0.1-SNAPSHOT</version>
<name>config-server</name>
<description>Demo project for Spring Boot</description>
<properties>
<java.version>1.8</java.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>Edgware.SR3</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
</project>
注意版本,这里用的1.5.3和Edgware.SR3,之前版本1.5.7和Edgware.SR3启动时报错:ApplicationEventMulticaster not initialized
5、启动后可以访问了
浏览器输入:http://127.0.0.1:7001/didispace-dev.properties,即可返回文件内容