springCloud入门(一)分布式配置管理
来源:互联网 发布:软件测试大赛 编辑:程序博客网 时间:2024/05/18 03:04
使用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>springCloud</groupId> <artifactId>configServer</artifactId> <version>1.0-SNAPSHOT</version> <packaging>jar</packaging> <name>configServer</name> <url>http://maven.apache.org</url> <parent> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-parent</artifactId> <version>Brixton.BUILD-SNAPSHOT</version> <relativePath /> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> </properties> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-config-server</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> </dependency> </dependencies> <repositories> <repository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>http://repo.spring.io/libs-snapshot-local</url> <snapshots> <enabled>true</enabled> </snapshots> </repository> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>http://repo.spring.io/libs-milestone-local</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <id>spring-releases</id> <name>Spring Releases</name> <url>http://repo.spring.io/libs-release-local</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> <defaultGoal>compile</defaultGoal> </build> <pluginRepositories> <pluginRepository> <id>spring-snapshots</id> <name>Spring Snapshots</name> <url>http://repo.spring.io/libs-snapshot-local</url> <snapshots> <enabled>true</enabled> </snapshots> </pluginRepository> <pluginRepository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>http://repo.spring.io/libs-milestone-local</url> <snapshots> <enabled>false</enabled> </snapshots> </pluginRepository> </pluginRepositories></project>
配置文件:application.properties
server.port=8888spring.cloud.config.server.git.uri=https://gitee.com/ren365880/spring-cloud-demo-config.gitspring.cloud.config.server.git.searchPaths=cloud-config-repospring.cloud.config.label=masterspring.application.name=cloud-config-server
启动类:ConfigServerApplication
import org.springframework.boot.SpringApplication;import org.springframework.boot.autoconfigure.EnableAutoConfiguration;import org.springframework.boot.autoconfigure.SpringBootApplication;import org.springframework.cloud.config.server.EnableConfigServer;
@EnableDiscoveryClient@SpringBootApplication@EnableConfigServer@EnableAutoConfigurationpublic class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); }}说明:maven的配置就不用说了,都是依赖的包
配置文件:springcloud配置管理可读取git文件,所以需要在git上新建项目,url出填写git地址,searchPaths填写文件所在文件夹,label是分支
启动main后访问127.0.0.1:端口/文件前缀/不同标识/即可获得配置文件的内容。
访问关系:
/{application}/{profile}[/{label}]
/{application}-{profile}.yml
/{label}/{application}-{profile}.yml
/{application}-{profile}.properties
/{label}/{application}-{profile}.properties
上面的url会映射{application}-{profile}.properties对应的配置文件,{label}对应git上不同的分支
返回内容:
项目和git目录
阅读全文
0 0
- springCloud入门(一)分布式配置管理
- 【SpringCloud】(一):SpringCloud入门程序
- springCloud入门(二)eureka分布式注册中心
- 分布式配置管理平台Jconf设计与实现(一)
- SpringCloud系列一----SpringBoot入门
- SpringCloud分布式开发五大神兽(一)
- springcloud入门(1)
- SpringCloud(第 028 篇)ConfigServer 配置管理微服务
- Springcloud学习(一)
- springcloud学习(一)
- spring cloud系列一 搭建配置服务器(分布式配置管理)configserver
- SpringCloud之Feign(一)
- SpringCloud学习笔记(一)
- SpringCloud之Ribbon(一)
- 配置管理入门
- springCloud(一)
- SpringCloud构建微服务入门架构(一)服务注册与发现
- SpringCloud 分布式配置
- 省份简称
- NYOJ C : zqw的梦幻之旅
- 双目+rtabmap_ros三维建图
- x86_64栈帧结构
- HDU 4501:小明系列故事——买年货
- springCloud入门(一)分布式配置管理
- 节点对象方法
- 关于Weblogic异常:weblogic.servlet.jsp.compilationException解决方案
- 正向代理与反向代理的区别
- 让你彻底明白JAVA中堆与栈的区别
- 缺少MySQLdb 模块,pip install MySQL-python 异常
- 几种求函数最值的算法
- 跨浏览器的事件处理、事件对象
- Netty实战读书笔记(第五章(一))