spring cloud系列一 搭建配置服务器(分布式配置管理)configserver
2017-08-17 17:50
477 查看
分布式配置管理应该是分布式系统和微服务应用的第一步。想象一下如果你有几十个服务或应用需要配置,而且每个服务还分为开发、测试、生产等不同维度的配置,那工作量是相当大的,而且还容易出错。如果能把各个应用的配置信息集中管理起来,使用一套机制或系统来管理,那么将极大的提高系统开发的生产效率,同时也会提高系统开发环境和生产环境运行的一致性。
1、pom.xml
<parent>
<groupId>org.springframework.boot</groupId> 引入boot
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>引入spring cloud
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>引入config-server
jar
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
2、启动类
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
3、配置文件
=====application.properties
server.port=8888
#spring.cloud.config.server.git.uri=http://git.oschina.net/zhou666/spring-cloud-7simple/tree/master/cloud-config-repo
#spring.cloud.config.server.git.searchPaths=cloud-config-repo
#eureka.client.serviceUrl.defaultZone=http\://localhost\:8761/eureka/,http\://zlhost\:8762/eureka/
spring.application.name=config-server
#使用本地属性文件
spring.profiles.active = native
#属性文件地址,只要指定文件夹的路径
spring.cloud.config.server.native.searchLocations=classpath:/properties/
====configServer-dev.properties
spring.datasource.url: jdbc:mysql://localhost/test
#spring.datasource.url = jdbc:h2:file:~/.h2/testdb
spring.datasource.username: root
spring.datasource.password: root
driver-class-name: com.mysql.jdbc.Driver
spring.jpa.database=MySQL
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
4、浏览器访问
http://127.0.0.1:8888/configServer/dev
5、客户端使用configserver
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
配置bootstrap.properties
#指定配置中心
spring.cloud.config.uri:http://127.0.0.1:8888
#指定属性文件名 configServer-dev.properties,是有命名规则的
spring.cloud.config.name=configServer
spring.cloud.config.profile=${profile:dev}
1、pom.xml
<parent>
<groupId>org.springframework.boot</groupId> 引入boot
<artifactId>spring-boot-starter-parent</artifactId>
<version>1.5.4.RELEASE</version>
</parent>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>引入spring cloud
<artifactId>spring-cloud-dependencies</artifactId>
<version>Dalston.SR2</version>
<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>引入config-server
jar
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
2、启动类
@SpringBootApplication
@EnableConfigServer
public class ConfigServerApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigServerApplication.class, args);
}
}
3、配置文件
=====application.properties
server.port=8888
#spring.cloud.config.server.git.uri=http://git.oschina.net/zhou666/spring-cloud-7simple/tree/master/cloud-config-repo
#spring.cloud.config.server.git.searchPaths=cloud-config-repo
#eureka.client.serviceUrl.defaultZone=http\://localhost\:8761/eureka/,http\://zlhost\:8762/eureka/
spring.application.name=config-server
#使用本地属性文件
spring.profiles.active = native
#属性文件地址,只要指定文件夹的路径
spring.cloud.config.server.native.searchLocations=classpath:/properties/
====configServer-dev.properties
spring.datasource.url: jdbc:mysql://localhost/test
#spring.datasource.url = jdbc:h2:file:~/.h2/testdb
spring.datasource.username: root
spring.datasource.password: root
driver-class-name: com.mysql.jdbc.Driver
spring.jpa.database=MySQL
spring.jpa.show-sql=true
spring.jpa.generate-ddl=true
spring.jpa.hibernate.ddl-auto=update
spring.jpa.hibernate.naming_strategy=org.hibernate.cfg.ImprovedNamingStrategy
4、浏览器访问
http://127.0.0.1:8888/configServer/dev
5、客户端使用configserver
pom.xml
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-config</artifactId>
</dependency>
配置bootstrap.properties
#指定配置中心
spring.cloud.config.uri:http://127.0.0.1:8888
#指定属性文件名 configServer-dev.properties,是有命名规则的
spring.cloud.config.name=configServer
spring.cloud.config.profile=${profile:dev}
相关文章推荐
- Hadoop系列~环境搭建,单机/伪分布式配置(一)
- Puppet系列之二:自动化配置管理平台的搭建
- 使用spring cloud实现分布式配置管理
- 使用spring cloud实现分布式配置管理
- 使用spring cloud实现分布式配置管理
- spring cloud系列-02.配置中心Config搭建
- 分布式配置管理--百度disconf搭建过程和详细使用
- 使用spring cloud实现分布式配置管理
- (pomelo系列入门教程)深入浅出Node.js游戏服务器开发--分布式聊天服务器搭建
- Spring Cloud(十)高可用的分布式配置中心 Spring Cloud Config 中使用 Refresh
- 一款轻量的分布式配置管理平台
- 利用vCloud Director搭建私有云环境系列之四:组织的管理
- 搭建git服务器及配置gitosis管理用户权限
- SOA 之路 -- Spring Cloud配置文件的统一管理
- mantis缺陷管理系统的搭建与配置
- 大数据系列(1)——Hadoop集群坏境搭建配置
- hadoop2.5.x完全分布式集群搭建配置
- Android下的配置管理之道之Android编译环境搭建
- Java Web学习总结(23)——Distributed Configuration Management Platform(分布式配置管理平台)
- 分布式缓存技术redis学习系列(四)——redis高级应用(集群搭建、集群分区原理、集群操作)