Spring Cloud Config配置管理开发工具包,可以让你把配置放到远程服务器,目前支持本地存储、Git以及Subversion。
说明:本示例采用的本地方式
一、创建pom项目:zx_springcloud_demo
pom.xml主要配置信息:
<parent>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-starter-parent</artifactId>
<version>Finchley.SR1</version>
</parent>
<groupId>com.zx.springcloud</groupId>
<artifactId>zx_springcloud_demo</artifactId>
<version>1.0</version>
<packaging>pom</packaging>
二、创建module之配置中心服务zx-config
1.pom.xml的主要配置
<parent>
<artifactId>zx_springcloud_demo</artifactId>
<groupId>com.zx.springcloud</groupId>
<version>1.0</version>
</parent>
<name>zx-config</name>
<artifactId>zx-config</artifactId>
<groupId>com.zx.springcloud</groupId>
<packaging>jar</packaging>
<dependencies>
<dependency>
<groupId>org.springframework.cloud</groupId>
<artifactId>spring-cloud-config-server</artifactId>
</dependency>
</dependencies>
主要依赖:spring-cloud-config-server
2. aplication.yml主要配置:
配置说明:
server.port为应用启动端口
logging.config加载日志配置文件(本示例采用的logback)
3. bootstrap.yml主要配置:
spring.profiles.active: native采用本地方式
spring.cloud.config.server.native.search-locations加载本地的配置文件
4.项目启动类:
程序入口启动类加上@EnableConfigServer注解开启配置服务器的功能,代码如下:
@EnableConfigServer
@SpringBootApplication
public class ConfigApplication {
public static void main(String[] args) {
SpringApplication.run(ConfigApplication.class, args);
}
}
本文项目源码地址:
https://github.com/cdzxkj/zx_springcloud_demo
转载请注明来自:
https://blog.csdn.net/javanian
欢迎访问博主的独立站: