spring cloud config server 配置中心
来源:互联网 发布:什么营销软件最好 编辑:程序博客网 时间:2024/05/01 06:24
spring cloud config 配置中心
配置中心分为 server 服务端 client 和客户端,
服务端搭建
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> <parent> <!-- spring boot 继承 --> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.5.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <groupId>com.cyy</groupId> <artifactId>my-spring-cloud-config-server</artifactId> <version>1.0.0-SNAPSHOT</version> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Brixton.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <!-- 添加 config-server 依赖 --> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project>
package app;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.config.server.EnableConfigServer;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/** * Created by Administrator on 2017/8/16. */@SpringBootApplication @EnableConfigServer // 配置中心服务public class ConfigSreviceApplication { public static void main(String [] args){ SpringApplication.run(ConfigSreviceApplication.class); }}
properties 配置
server.port=4555#git 仓库地址spring.cloud.config.server.git.uri=https://github.com/cyyinfo/spring-cloud-config-demo.git#如果配置文件不在仓库的根目录则需要配置此项,为配置文件所在目录spring.cloud.config.server.git.search-paths=config-repository
到这里一个最简单的配置服务端搭建完成,启动后访问
http://localhost:4555/spring-cloud-config-sevice-demo/master 可以看到结果
http://localhost:4555/[git 仓库项目名称]/[profile 默认master]
client 端搭建
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> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.3.5.RELEASE</version> <relativePath /> <!-- lookup parent from repository --> </parent> <groupId>com.cyy</groupId> <artifactId>my-spring-cloud-config-client</artifactId> <version>1.0.0-SNAPSHOT</version> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Brixton.RELEASE</version> <type>pom</type> <scope>import</scope> </dependency> </dependencies> </dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-client</artifactId> </dependency> </dependencies> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build></project>启动类
package app;import org.springframework.beans.factory.annotation.Value;import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.web.bind.annotation.RequestMapping;import org.springframework.web.bind.annotation.RestController;/** * Created by Administrator on 2017/8/16. */@RestController@SpringBootApplication@RequestMapping("/")public class ConfigClientApplication { @Value("${test.demo.name}") private String testDemoName; @RequestMapping("") public String index(){ return "config clicent testDemoName="+this.testDemoName+"#"; } public static void main(String [] args){ SpringApplication.run(ConfigClientApplication.class); }}配置文件 注意是 bootstrap.properties 而不是 application.properties
spring.cloud.config.env=spring-cloud-config-sevice-demo // git 仓库名称spring.cloud.config.profile=prev // 配置氮气环境 决定是加载git仓库中的 application-prev.propertis haishispring.cloud.config.label=master // git 分支名 spring.cloud.config.uri=http://localhost:4555 // 配置中心项目访问地址spring.application.name=my-config-clientserver.port=4556完整 demo 地址
https://github.com/cyyinfo/spring-cloud-config-demo.git
阅读全文
0 0
- spring cloud config server 配置中心
- 配置中心:Spring Cloud Config
- 使用Spring Cloud Config搭建配置中心
- 使用Spring Cloud Config搭建配置中心
- spring cloud config统一配置中心
- Spring Cloud Config 配置中心 教程
- Spring Cloud入门1-config配置中心
- SpringCloud: 分布式配置中心(Spring Cloud Config)
- 分布式配置中心Spring Cloud Config初窥
- Spring Cloud学习--配置中心(Config)
- Spring Cloud (5) | 配置中心 Config Server 配置git or github or gitlab
- spring cloud config server使用svn来作为外部配置中心
- 非spring 工程使用 spring cloud config配置中心
- Spring Cloud Config Server 配置总结
- spring cloud config整合gitlab搭建分布式的配置中心
- spring cloud config分布式配置中心的高可用
- Spring Cloud入门2——配置中心Config
- spring cloud config整合gitlab搭建分布式的配置中心
- java后台测试代码向数据库写入的date类型的值始终为1970-01-01解决方法
- WebSocket使用之API
- Dropout:A Simple Way to Prevent Neural Networks from Overfitting
- hdu6153A Secret(扩展KMP)
- matlab错误使用 mex 未找到支持的编译器或 SDK
- spring cloud config server 配置中心
- Android Toolbar使用系统原生返回键,并改变其颜色,自定义图片替换系统原生返回键
- 设计模式之命令模式
- 总结下使用git上传项目到github
- ArgumentException: Getting control 0's position in a group with only 0 controls when doing Repaint A
- 反射第四步 : 通过反射获取某一个类的 方法 并通过反射调用
- sublime 常用插件 0.0
- 包装类,基本类和字符串之间转换2
- 极光推送 tag alias 设置