SpringCloudConfig配置服务器搭建与使用
程序员文章站
2022-07-04 16:01:20
...
1、SpringCloudConfig 配置服务Config Server 搭建
使用idea创建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 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>com.lww</groupId>
<artifactId>config</artifactId>
<version>0.0.1-SNAPSHOT</version>
<packaging>jar</packaging>
<name>config</name>
<description>Demo project for Spring Boot</description>
<parent>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
<relativePath/> <!-- lookup parent from repository -->
</parent>
<properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<java.version>1.8</java.version>
<spring-cloud.version>Dalston.SR1</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-web</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-eureka</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-test</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
</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>
</plugin>
</plugins>
</build>
</project>
在启动类上添加注解:@EnableConfigServer (关键)
配置文件application.yml
server:
port: 8888
spring:
cloud:
config:
server:
git:
uri: https://github.com/luww/springconfig.git
label: master
##searchPaths: blob
#uri: https://git.oschina.net/gongxusheng/spring-config-demo.git
#searchPaths: my-sample-config
在git上创建一个文件
2、Config-Client 使用
pom.xml 在dependencys增加
<!-- Spring Cloud Config Client -->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-client</artifactId>
</dependency>
pom.xml 在project增加
<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>
在application.yml添加配置
spring:
application:
name: my-client
cloud:
config:
uri: http://127.0.0.1:8888
label: master
创建一个测试Controller
出现如下调用成功
上一篇: STM32F1学习笔记
下一篇: Eureka服务器 (简易版)
推荐阅读
-
javaWeb使用servlet搭建服务器入门
-
MySQL(win7x64 5.7.16版本)下载、安装、配置与使用的详细图文教程
-
使用IDEA配置Maven搭建开发框架ssm教程
-
探讨:使用httpClient在客户端与服务器端传输对象参数的详解
-
Spring Boot 与 Kotlin 使用Redis数据库的配置方法
-
Nginx搭建HTTPS服务器和强制使用HTTPS访问的方法
-
NetCoreApi框架搭建(二、Nllog使用配置)
-
Android开发使用json实现服务器与客户端数据的交互功能示例
-
MySQL(win7x64 5.7.16版本)下载、安装、配置与使用的详细图文教程
-
详解Maven环境的搭建与idea配置