内容简介:当修改一个配置文件,我们需要重新打包项目或重新启动服务才能生效,springcloud的config实现了配置文件的统一管理,当配置文件修改后提交Git后系统会自动刷新获取修改后的配置文件。
当修改一个配置文件,我们需要重新打包项目或重新启动服务才能生效,springcloud的config实现了配置文件的统一管理,当配置文件修改后提交Git后系统会自动刷新获取修改后的配置文件。
- 将配置文件上传至Git上
新建一个maven项目:
建好的项目结构如下:
- pom文件相关依赖
<?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> <groupId>cloud</groupId> <artifactId>cloud-config-server</artifactId> <version>0.0.1-SNAPSHOT</version> <packaging>jar</packaging> <name>cloud-config-server</name> <description>Demo project for Spring Boot</description> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>1.5.10.RELEASE</version> <relativePath/> <!-- lookup parent from repository --> </parent> <properties> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding> <java.version>1.8</java.version> <spring-cloud.version>Greenwich.M3</spring-cloud.version> </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</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency> </dependencies> <dependencyManagement> <dependencies> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-dependencies</artifactId> <version>Dalston.SR3</version> <type>pom</type> <scope>import</scope> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka-server</artifactId> <exclusions> <exclusion> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-xml</artifactId> </exclusion> </exclusions> </dependency> </dependencies> </dependencyManagement> <build> <finalName>${project.artifactId}</finalName> <plugins> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-resources-plugin</artifactId> <configuration> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>1.8</source> <target>1.8</target> <encoding>UTF-8</encoding> </configuration> </plugin> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> </plugins> </build> <repositories> <repository> <id>spring-milestones</id> <name>Spring Milestones</name> <url>https://repo.spring.io/milestone</url> <snapshots> <enabled>false</enabled> </snapshots> </repository> </repositories> </project> 复制代码
- 启动文件
@EnableDiscoveryClient @SpringBootApplication @EnableConfigServer public class ConfigServerApplication { public static void main(String[] args) { SpringApplication.run(ConfigServerApplication.class, args); } } 复制代码
- 服务器端配置文件详情
server.port=8081 spring.cloud.config.server.git.uri=https://github.com/castanea-kang/config-repo.git spring.cloud.config.server.git.searchPaths=cloud-config-repo spring.application.name=cloud-config spring.cloud.config.discovery.enabled=true spring.cloud.config.discovery.service-id=cloud-config spring.rabbitmq.host=114.115.243.135 spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest eureka.client.serviceUrl.defaultZone=http://eureka01:8080/eureka/ #eureka.instance.prefer-ip-address=true #eureka.instance.ip-address=114.115.243.135 #配置从eureka注册中心访问接口的ip #eureka.instance.status-page-url-path=/cloud-config/test/ #接口访问路径 management.security.enabled=false #是否开启安全认证 复制代码
- 启动config server端可以再eureka注册中心找到该服务,如下图:
可以通过访问地址http://114.115.243.135:8081/cloud-config/test/ 得到数据:
config客户端相关配置
- pom配置文件相关依赖
<dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-config</artifactId> </dependency> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-eureka</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-actuator</artifactId> </dependency> <!-- 总线刷新,通过rabbitmq --> <dependency> <groupId>org.springframework.cloud</groupId> <artifactId>spring-cloud-starter-bus-amqp</artifactId> </dependency> 复制代码
- 配置文件详情bootstrap.properties
spring.application.name=cloud-config spring.cloud.config.profile=test eureka.client.serviceUrl.defaultZone=http://114.115.243.135:8080/eureka/ spring.cloud.config.discovery.enabled=true spring.cloud.config.discovery.service-id=cloud-config eureka.client.register-with-eureka=false spring.rabbitmq.host=114.115.243.135 spring.rabbitmq.port=5672 spring.rabbitmq.username=guest spring.rabbitmq.password=guest management.security.enabled=false spring.cloud.bus.trace.enabled=true 复制代码
- 利用git的webhook实现实时更新通知,当向git进行事件操作时,进行配置文件刷新应用。
注:如果出现配置正常刷新日志打印正常,但是并没有刷新,在config client 控制层上加上注解
@RefreshScope
以上所述就是小编给大家介绍的《springcloud 配置文件管理动态刷新》,希望对大家有所帮助,如果大家有任何疑问请给我留言,小编会及时回复大家的。在此也非常感谢大家对 码农网 的支持!
猜你喜欢:- Nacos 自动刷新配置如何实现的?
- nginx配置 vue打包后的项目 解决刷新页面404问题|nginx配置多端访问
- 原 荐 白话SpringCloud | 第八章:分布式配置中心的服务化及动态刷新
- ApiBoot v2.2.6 发布,新增配置客户端 OAuth2 刷新令牌过期时间
- Spring Cloud之Finchley版学习(二十二)-Spring Cloud Config-配置动态刷新
- Swift iOS : 上拉刷新或者下拉刷新
本站部分资源来源于网络,本站转载出于传递更多信息之目的,版权归原作者或者来源机构所有,如转载稿涉及版权问题,请联系我们。
The Lambda Calculus, Its Syntax and Semantics . Revised Edition
H.P. Barendregt / North Holland / 1985-11-15 / USD 133.00
The revised edition contains a new chapter which provides an elegant description of the semantics. The various classes of lambda calculus models are described in a uniform manner. Some didactical impr......一起来看看 《The Lambda Calculus, Its Syntax and Semantics . Revised Edition》 这本书的介绍吧!