1.配置 spring cloud 的远程服务中心 ,需要先在Git上生成一个仓库。在仓库中配置 .properties 文件
配置连接数据库的四要素
2 .然后创建本地maven文件 在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>
<groupId>cn.et</groupId>
<artifactId>SpringCloud_ConfigServer</artifactId>
<version>0.0.1-SNAPSHOT</version>
<!-- 依赖springboot -->
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.9.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR4</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<!-- 配置远程中心 -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
</project>
3.在maven项目的src/main/resources 创建一个application.properties文件。在文件中配置 仓库的地址 和给仓库配置一个端口 仓库的地址后缀的.git 要去掉
spring.cloud.config.server.git.uri= https://github.com/zmw0221/SpringCloud
server.port=8089
4.最后 一个带main方法的类用来启动 服务
package cn.et;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
//必须添加SpringbootApplication 启用Spring的自动配置功能
//要扫描添加@ComponentScan(扫描的包名)
@SpringBootApplication
/**
* 启用分布式配置中心 读取远程git仓库获取配置
* 所有spring的配置中心的配置文件 都有以下几种格式组成
* 1 配置文件属于哪个应用的(application)
* 2 配置文件属于哪个 阶段(profile) 开发阶段 测试阶段 产品阶段
* 3 在git中的哪个分支(label)
*/
@EnableConfigServer
public class Main {
public static void main(String[] args) {
SpringApplication.run(Main.class, args);
}
}
5.在浏览器中输入路径 看是否能访问 远程服务中心