spring cloud config 用svn做配置文件仓库

本文介绍如何使用Spring Cloud Config Server与SVN集成实现外部配置管理。文章详细描述了搭建配置服务器及客户端的具体步骤,并提供了关键代码示例。

刚接触spring cloud 的 ;做了一个svn做配置文件仓库demo;


创建一个spring boot工程作为 spring  cloud config  server ;下面是pom.xml文件;

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"  
  3.          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  5.     <modelVersion>4.0.0</modelVersion>  
  6.   
  7.     <parent>  
  8.         <groupId>org.springframework.boot</groupId>  
  9.         <artifactId>spring-boot-starter-parent</artifactId>  
  10.         <version>1.2.3.RELEASE</version>  
  11.         <relativePath /> <!-- lookup parent from repository -->  
  12.     </parent>  
  13.   
  14.     <groupId>com.honkib.springcloud</groupId>  
  15.     <artifactId>spring-cloud-config-server</artifactId>  
  16.     <version>1.0-SNAPSHOT</version>  
  17.   
  18.     <dependencyManagement>  
  19.         <dependencies>  
  20.             <dependency>  
  21.                 <groupId>org.springframework.cloud</groupId>  
  22.                 <artifactId>spring-cloud-config</artifactId>  
  23.                 <version>1.0.4.RELEASE</version>  
  24.                 <type>pom</type>  
  25.                 <scope>import</scope>  
  26.             </dependency>  
  27.         </dependencies>  
  28.     </dependencyManagement>  
  29.     <dependencies>  
  30.         <dependency>  
  31.             <groupId>org.springframework.cloud</groupId>  
  32.             <artifactId>spring-cloud-starter-config</artifactId>  
  33.         </dependency>  
  34.   
  35.         <!--表示为web工程-->  
  36.         <dependency>  
  37.             <groupId>org.springframework.boot</groupId>  
  38.             <artifactId>spring-boot-starter-web</artifactId>  
  39.         </dependency>  
  40.   
  41.         <!--暴露各种指标-->  
  42.         <dependency>  
  43.             <groupId>org.springframework.boot</groupId>  
  44.             <artifactId>spring-boot-starter-actuator</artifactId>  
  45.         </dependency>  
  46.   
  47.         <dependency>  
  48.             <groupId>org.springframework.cloud</groupId>  
  49.             <artifactId>spring-cloud-config-server</artifactId>  
  50.         </dependency>  
  51.           
  52.          <!--config server need read svn-->  
  53.         <dependency>  
  54.             <groupId>org.tmatesoft.svnkit</groupId>  
  55.             <artifactId>svnkit</artifactId>  
  56.             <version>1.8.10</version>  
  57.         </dependency>  
  58.   
  59.     </dependencies>  
  60.   
  61.     <build>  
  62.         <plugins>  
  63.             <plugin>  
  64.                 <groupId>org.springframework.boot</groupId>  
  65.                 <artifactId>spring-boot-maven-plugin</artifactId>  
  66.             </plugin>  
  67.         </plugins>  
  68.     </build>  
  69.   
  70. </project>  

configserver程序结构:


然后创建一个application.java 类

[java]  view plain  copy
  1. package com.hobkib.cloud.demo;  
  2.   
  3. import org.springframework.boot.SpringApplication;  
  4. import org.springframework.boot.autoconfigure.EnableAutoConfiguration;  
  5. import org.springframework.boot.autoconfigure.SpringBootApplication;  
  6. import org.springframework.cloud.config.server.EnableConfigServer;  
  7. import org.springframework.context.annotation.Configuration;  
  8. import org.springframework.web.bind.annotation.RestController;  
  9.   
  10. /** 
  11.  * Created by liaokailin on 16/4/28. 
  12.  */  
  13.   
  14. @Configuration  
  15. @EnableAutoConfiguration  
  16. @EnableConfigServer  
  17. public class Application {  
  18.   
  19.     public static void main(String[] args) {  
  20.         SpringApplication.run(Application.class, args);  
  21.     }  
  22.       
  23. }  

其中@ EnableConfigServer 为作为配置文件服务的注解;


appliction.yml配置文件:

[html]  view plain  copy
  1. server:  
  2.   port: 8888  
  3.   
  4. spring:  
  5.   cloud:  
  6.     config:  
  7.       enabled: true  
  8.       server:  
  9.         svn:  
  10.           uri: http://192.168.0.66/svn/cloudconfig/  
  11.           username: chenhua  
  12.           password: 123456  
  13.         #git:  
  14.         #  uri: https://github.com/pcf-guides/configuration-server-config-repo  
  15.         default-label: config  
  16.   profiles:  
  17.     active: subversion  
  18.   
  19. logging:  
  20.   levels:  
  21.     org.springframework.boot.env.PropertySourcesLoader: TRACE  
  22.     org.springframework.cloud.config.server: DEBUG  



创建一个svn仓库作为spring cloud 的配置文件库;



这张图片中配置文件的结构写错了;

配置文件的结构应该是在客户端的 配置文件appliction.preperties文件中的两个字段;(spring.cloud.config.name  和  spring.cloud.config.profile)

       要符合{spring.cloud.config.name}-{spring.cloud.config.profile}.preperties 或者后缀为.yml的配置文件;


创建svn库后一定要创建一个文件夹;(必须的),不知道是是不是读取库的问题;默认情况下,他会去这你提供的svn库uri中的trunk文件夹下读取(可以配置这个文件夹的名称。配置成空默认去trunk文件夹查找配置文件),配置文件不能放到svn的根目录下(默认去trunk的文件夹下找配置文件);


客户端工程:

客户端的工程结构:

客户端的配置文件:

[html]  view plain  copy
  1. <?xml version="1.0" encoding="UTF-8"?>  
  2. <project xmlns="http://maven.apache.org/POM/4.0.0"  
  3.          xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"  
  4.          xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">  
  5.     <modelVersion>4.0.0</modelVersion>  
  6.   
  7.     <groupId>com.honkib.springcloud</groupId>  
  8.     <artifactId>spring-cloud-config-client</artifactId>  
  9.     <version>1.0-SNAPSHOT</version>  
  10.   
  11.   
  12.     <parent>  
  13.         <groupId>org.springframework.boot</groupId>  
  14.         <artifactId>spring-boot-starter-parent</artifactId>  
  15.         <version>1.2.3.RELEASE</version>  
  16.         <relativePath /> <!-- lookup parent from repository -->  
  17.     </parent>  
  18.       
  19.   
  20.   
  21.     <dependencyManagement>  
  22.         <dependencies>  
  23.             <dependency>  
  24.                 <groupId>org.springframework.cloud</groupId>  
  25.                 <artifactId>spring-cloud-starter-parent</artifactId>  
  26.                 <version>1.0.1.RELEASE</version>  
  27.                 <type>pom</type>  
  28.                 <scope>import</scope>  
  29.             </dependency>  
  30.         </dependencies>  
  31.     </dependencyManagement>  
  32.   
  33.   
  34.     <dependencies>  
  35.         <dependency>  
  36.             <groupId>org.springframework.boot</groupId>  
  37.             <artifactId>spring-boot-starter-web</artifactId>  
  38.         </dependency>  
  39.         <dependency>  
  40.             <groupId>org.springframework.cloud</groupId>  
  41.             <artifactId>spring-cloud-config-client</artifactId>  
  42.         </dependency>  
  43.         <dependency>  
  44.             <groupId>org.springframework.boot</groupId>  
  45.             <artifactId>spring-boot-starter-actuator</artifactId>  
  46.         </dependency>  
  47.   
  48.         <dependency>  
  49.             <groupId>org.springframework.boot</groupId>  
  50.             <artifactId>spring-boot-starter-test</artifactId>  
  51.             <scope>test</scope>  
  52.         </dependency>  
  53.           
  54.         <dependency>  
  55.             <groupId>org.springframework.boot</groupId>  
  56.             <artifactId>spring-boot-starter-actuator</artifactId>  
  57.         </dependency>  
  58.           
  59.     </dependencies>  
  60.     <repositories>  
  61.         <repository>  
  62.             <id>spring-milestones</id>  
  63.             <name>Spring Milestones</name>  
  64.             <url>http://repo.spring.io/milestone</url>  
  65.             <snapshots>  
  66.                 <enabled>false</enabled>  
  67.             </snapshots>  
  68.         </repository>  
  69.     </repositories>  
  70.     <pluginRepositories>  
  71.         <pluginRepository>  
  72.             <id>spring-milestones</id>  
  73.             <name>Spring Milestones</name>  
  74.             <url>http://repo.spring.io/milestone</url>  
  75.             <snapshots>  
  76.                 <enabled>false</enabled>  
  77.             </snapshots>  
  78.         </pluginRepository>  
  79.     </pluginRepositories>  
  80.   
  81.     <build>  
  82.         <plugins>  
  83.             <plugin>  
  84.                 <groupId>org.springframework.boot</groupId>  
  85.                 <artifactId>spring-boot-maven-plugin</artifactId>  
  86.             </plugin>  
  87.         </plugins>  
  88.     </build>  
  89. </project>  

appliction.java

[java]  view plain  copy
  1. package com.hobkib.cloud.democlient;  
  2.   
  3. import org.springframework.beans.factory.annotation.Value;  
  4. import org.springframework.boot.SpringApplication;  
  5. import org.springframework.boot.autoconfigure.SpringBootApplication;  
  6. import org.springframework.web.bind.annotation.RequestMapping;  
  7. import org.springframework.web.bind.annotation.RestController;  
  8.   
  9. /** 
  10.  * Created by liaokailin on 16/4/28. 
  11.  */  
  12. @SpringBootApplication  
  13. @RestController  
  14. public class Application {  
  15.     @Value("${mysqldb.datasource.url:World}")  
  16.     String bar;  
  17.   
  18.     @RequestMapping("/")  
  19.     String hello() {  
  20.         return "Hello " + bar + "!";  
  21.     }  
  22.   
  23.     public static void main(String[] args) {  
  24.         SpringApplication.run(Application.class, args);  
  25.     }  
  26. }  

bootstrap.preperties 配置文件:

[html]  view plain  copy
  1. server.port=8081  
  2. spring.cloud.config.uri=http://localhost:${config.port:8888}  
  3. spring.cloud.config.name=cloud-config  
  4. spring.cloud.config.profile=${config.profile:dev}  
  5.   
  6. spring.application.name=cloud-simple-service  


这样程序就已经完成了;


接下来就是运行程序了;

先启动configserver 程序;

然后再启动client工程;

成功了的话;我们应该能在client程序的日志中看到这么一条日志:

2017-02-16 15:32:54.209  INFO 9836 --- [           main] b.c.PropertySourceBootstrapConfiguration : Located property source: CompositePropertySource [name='configService', propertySources=[MapPropertySource [name='http://192.168.0.66/svn/cloudconfig/config/cloud-config-dev.properties']]]

这就表明已经读取到日志了;

接下来只要在@Value("${key}")就可以获取到配置文件的值了;

或者好用env.getPreperty来获取配置文件信息;


注:很重要的一点;不知道的是什么问题;configserver服务端一定要用yml配置文件,使用preperties配置文件启动不成功;不识别;

还有就是注意svn的文件目录结构;配置文件名称结构

内容概要:本文提出了一种基于改进扩散模型的高海拔地区新能源高波动出力场景生成方法,并提供了完整的Python代码实现。该方法针对高海拔地区风能、光伏等新能源出力波动剧烈、不确定性高的特点,通过优化扩散模型的结构与训练策略,有效捕捉历史数据的概率分布特征与时序相关性,从而生成高质量、多样化的出力场景。文中详细阐述了模型的数学推导、网络架构设计、损失函数优化及采样算法改进,并通过实验证明其在拟合精度、场景多样性与稳定性方面优于传统生成模型,为电力系统在高比例新能源接入下的规划、调度与风险评估提供了可靠的场景输入支持。; 适合人群:具备一定Python编程能力和机器学习基础,从事新能源发电预测、电力系统分析、智能优化、场景生成等方向研究的科研人员、高校研究生及工程技术人员。; 使用场景及目标:①用于高海拔地区风电、光伏出力的不确定性建模与多场景生成;②支撑含高渗透率新能源的电力系统随机优化调度、鲁棒决策与风险评估;③为相关学术研究、论文复现与算法改进提供可运行的技术方案与代码基础; 阅读建议:建议读者结合所提供的完整资源(代码、数据集、说明文档)进行实践操作,重点关注扩散模型的前向加噪与反向去噪过程的设计细节,以及如何将其适配于新能源时序数据的生成任务,通过参数调优与对比实验深入理解模型的生成机制与性能边界。
内容概要:本文围绕基于静态约束法的配电网电动汽车接入容量评估展开研究,提出了一种在新型电力系统背景下评估主动配电网对电动汽车承载能力的方法。研究通过构建数学模型,结合潮流计算与关键约束条件(如电压越限、线路过载等),量化分析配电网可承受的最大电动汽车充电负荷容量,旨在识别规模化电动汽车接入带来的潜在运行风险,并为电网规划与运行提供科学依据。文中配套提供了完整的Matlab代码实现,便于仿真验证与结果复现。此外,该研究与分布式光伏承载力评估、电动汽车可调能力分析等方向形成技术联动,展现了多主题协同的研究体系。; 适合人群:具备电力系统分析基础理论知识及Matlab编程能力的高校研究生、科研机构研究人员,以及从事新能源并网、智能配电网规划与运行等相关领域的工程技术人员。; 使用场景及目标:①用于学术研究中的模型复现与论文撰写支撑;②评估实际配电网中电动汽车大规模接入的可行性与安全边界,指导充电基础设施布局;③作为高校教学案例,帮助学生深入理解电网承载力评估的核心原理、建模方法与仿真技术; 阅读建议:建议结合文中提及的相关研究方向(如二阶锥规划、多面体聚合方法等)进行对比学习,充分利用所提供的Matlab代码与网盘资料开展仿真实验,重点关注约束条件的设定逻辑与潮流计算模块的实现细节,以深化对评估模型机理与工程应用价值的理解。
内容概要:本文围绕“考虑隐私保护的分布式联邦学习电力负荷预测研究”展开,提出了一种基于Python实现的联邦学习框架,旨在解决居民或行业电力负荷预测中用户电表数据隐私泄露的风险。该研究通过构建分布式机器学习模型,使各参与方在不共享原始数据的前提下协同训练全局模型,有效实现了数据“可用不可见”。文中详细阐述了联邦学习的整体架构设计、本地模型训练流程、参数加密传输与安全聚合机制,并结合差分隐私等技术进一步增强系统的隐私保护能力。同时,研究利用真实电力负荷数据集进行了实验验证,展示了方法在预测精度与隐私保障之间的良好平衡,并提供了完整的代码实例与复现指南,便于后续研究与应用拓展。; 适合人群:具备一定机器学习基础和电力系统背景知识,从事智慧能源、隐私计算或人工智能相关方向研究的研究生、科研人员及工程技术人员。; 使用场景及目标:① 实现跨区域、跨主体的电力负荷协同预测,打破数据孤岛;② 在确保用户用电数据隐私安全的前提下提升负荷预测准确性;③ 推动联邦学习在智能电网、需求响应、虚拟电厂等场景中的实际部署与应用。; 阅读建议:建议结合文中提供的Python代码与网盘资料进行动手实践,重点关注联邦学习的通信轮次设计、模型聚合算法(如FedAvg)的实现细节以及差分隐私噪声添加策略,深入理解其对模型性能与隐私强度的影响,为进一步优化与创新奠定基础。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值