Config分布式配置中心
程序员文章站
2022-07-03 18:12:33
...
Config分布式配置中心
包结构
依赖
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!--springCloud依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
application.properties
spring.application.name=config-server
server.port=8889
#
spring.cloud.config.server.git.uri=https://gitee.com/towfour/config.git
spring.cloud.config.server.git.searchPaths=respo
#分支
spring.cloud.config.label=master
spring.cloud.config.server.git.username=
spring.cloud.config.server.git.password=
spring.cloud.config.server.git.uri=填写https://gitee.com克隆/下载的HTTPS的路径
分支
启动类
package com.zzc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.EnableAutoConfiguration;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.cloud.config.server.EnableConfigServer;
/**
* Hello world!
*
*/
@SpringBootApplication
@EnableConfigServer
public class App
{
public static void main( String[] args )
{
SpringApplication.run(App.class,args);
}
}
springcloud_configclient
依赖
<dependencies>
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>4.11</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<!--springCloud依赖-->
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-dependencies</artifactId>
<version>Greenwich.RELEASE</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
ConfigClientController
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
@RestController
public class ConfigClientController {
@Value("${userName}")
String userName;
@RequestMapping("/getConfig")
public String getConfig(){
return userName;
}
}
bootstrap.properties
spring.application.name=config-client
#分支
spring.cloud.config.label=master
spring.cloud.config.profile=dev
#端口是SpringCloud_config_service的端口号
spring.cloud.config.uri= http://localhost:8889/
#自己的端口
server.port=8880
启动类
package com.zzc;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
/**
* Hello world!
*
*/
@SpringBootApplication
public class StartConfigClient
{
public static void main( String[] args )
{
SpringApplication.run(StartConfigClient.class,args);
}
}
运行结果
推荐阅读
-
Spring Cloud Config 配置中心实践过程中,你需要了解这些细节!
-
图解修改IIS web.config配置文件增设置默认文档的方法
-
Springcloud 2.x 版本 分布式配置中心
-
vue-cli3中vue.config.js配置教程详解
-
【Config】类库读取自己的配置文件,配置文件的扩展
-
基于ZooKeeper实现简单的配置中心
-
webpack教程之webpack.config.js配置文件
-
VS中C#读取app.config数据库配置字符串的三种方法
-
springboot配置文件抽离 git管理统 配置中心详解
-
Mycat分布式数据库架构解决方案--配置defaultAccount属性报错解决方案