/**
* ===============================================================================
* The Shenma Internet Financial Information Software License
*
* Copyright (c) 2017 Shenma Internet Financial Information Service Co., Ltd.
*
* @Company: xushenjk www.xushen.com
*
* @Project: shenma-samp-server
*
* @Author: Kaiyun.Fu
* @Created at 2017年12月2日下午9:06:52
* ===============================================================================
*/
package com.shenm.account.server.test;
import com.alibaba.fastjson.JSON;
import lombok.extern.slf4j.Slf4j;
import org.junit.Test;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.EncodedResource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.PropertiesLoaderUtils;
import org.springframework.core.io.support.ResourcePatternResolver;
import java.io.IOException;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.List;
import java.util.Properties;
/**
*
* @author gaohailiang
* @Created at 2017年12月2日下午9:06:52
*/
@Slf4j
public class ResourceTest {
@Test
public void testClasspathAsteriskPrefix()throws IOException{
ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver();
//将加载多个绝对匹配的所有Resource
//将首先通过ClassLoader.getResource("META-INF")加载非模式路径部分
//然后进行遍历模式匹配
// classpath*:*-test.properties
//Resource[] resources = (Resource[]) resolver.getResources("classpath*:META-INF/INDEX.LIST");
// Resource[] resources = (Resource[]) resolver.getResources("classpath*:*-test.properties");
Resource[] resources = resolver.getResources("classpath*:application-*.properties");
for(Resource resource:resources){
log.info(resource.getFilename());
}
// Assert.assertTrue(resources.length > 1);
//将加载多个模式匹配的Resource
// resources = (Resource[]) resolver.getResources("classpath*:META-INF/*.LIST");
// Assert.assertTrue(resources.length > 1);
}
private static final String SAMP = "shenma-samp";
private static final String EVN = "application-production";
/**
* 配置文件转Json 用于上传到配置中心
* @throws IOException
*/
@Test
public void printJson() throws IOException{
ResourcePatternResolver resolver = (ResourcePatternResolver) new PathMatchingResourcePatternResolver();
Resource[] resources = resolver.getResources("classpath*:"+EVN+".properties");
// Properties propertie = new Properties();
List<Properties> properties = new ArrayList<Properties>();
for (Resource rsrc : resources) {
log.info("Filename = "+rsrc.getFilename());
log.info("Description="+rsrc.getDescription());
// if(!rsrc.getDescription().contains(SAMP)){
// log.info(rsrc.getFilename()+ "不是 SAMP 工程配置文件,不解析.--"+rsrc.getDescription());
// continue;
// }
EncodedResource enrsrc = new EncodedResource(rsrc);
Properties tmpProperties = PropertiesLoaderUtils.loadProperties(enrsrc);
properties.add(tmpProperties);
}
List<XdiaConfig> list = new ArrayList<XdiaConfig>();
for (Properties p : properties) {
Enumeration<?> enu = p.propertyNames();
while (enu.hasMoreElements()) {
String key = (String) enu.nextElement();
XdiaConfig xc = new XdiaConfig(key, p.getProperty(key), key);
list.add(xc);
//propertie.setProperty(key, p.getProperty(key));
}
}
log.info("配置中心初始化全量Key Value:"+ JSON.toJSONString(list));
}
}
class XdiaConfig {
private String key;
private String value;
private String description;
/**
* @param key
* @param value
*/
public XdiaConfig(String key, String value, String description) {
super();
this.key = key;
this.value = value;
this.description = description;
}
public String getKey() {
return key;
}
public void setKey(String key) {
this.key = key;
}
public String getValue() {
return value;
}
public void setValue(String value) {
this.value = value;
}
public String getDescription() {
return description;
}
public void setDescription(String description) {
this.description = description;
}
}
spring 配置
<bean id="xDiamondConfig"
class="io.github.xdiamond.client.spring.XDiamondConfigFactoryBean">
<property name="serverHost" value="${com.shenma.xdiamond.serverHost}" />
<property name="serverPort" value="${com.shenma.xdiamond.serverPort}" />
<property name="groupId" value="${com.shenma.xdiamond.groupId}" />
<property name="artifactId" value="${com.shenma.xdiamond.artifactId}" />
<property name="version" value="${com.shenma.xdiamond.version}" />
<property name="bSyncToSystemProperties" value="${com.shenma.xdiamond.bSyncToSystemProperties}"/>
<property name="profile" value="${com.shenma.xdiamond.profile}" />
<property name="secretKey" value="${com.shenma.xdiamond.secretKey}"></property>
</bean>
分享到:
相关推荐
为了减少WAP网站的建设,企业可以使用Power Diamond通用WAP网站生成系统自动生成静态WAP网站,本系统只需要在XML文件中配置相关的参数,即可生成符合WML语法规范的.wml文件,将企业的信息在手机上广泛传播。
可以使用Power Diamond通用WAP网站生成系统自动生成静态WAP网站,本系统只需要在XML文件中配置相关的参数,即可生成符合WML语法规范的.wml文件,将企业的信息在手机上广泛传播,与现有系统无缝整合,自动将页面内容...
Polybar配置 NOTE:为了正确显示蓝牙图标,您将需要在栏中使用图标字体,例如 [module/bluetooth] type = custom/script exec = rofi-bluetooth --status interval = 1 click-left = rofi-bluetooth & i3键盘绑定 ...
reveal在线逻辑分析仪,包括rvl文件生成,触发条件获取信号的设置,rva文件的配置,波形观察等等
钻石运行时配置 将DIAMOND_LOG设置为某些内容以启用写入二进制日志。 或者,将DIAMOND_LOGFILE设置为二进制日志的文件名,或将DIAMOND_LOGDIR设置为将写入的目录。 钻石运行时 API 待办事项(见core.diamond.api ...
Diamond-Square Houdini SOP 这是我的到 Houdini SOP 的端口。 有关实现的更多详细信息,请参阅原始插件的页面(例如,它包装、迭代等)。 该端口也像原始端口一样。 要编译 SOP 并将其安装到本地 Houdini 目录, ...
Easy Accounting是一种独立于平台(可在Windows / Linux / Unix / Mac / Solaries等任何操作系统中运行)的教育软件,通过该软件,输入交易即可为多个公司或用户生成日记帐和分类帐。 版本:1.0.0(于2014年3月31日...
用DSL编写的流程配置文件正在由解析器(在Ruby上)进行分析,并基于模拟器框架类生成高性能的C ++代码。 介绍的语言描述。 分析仪 DSL由分析器解释并生成概念依存关系图(例如,使用的配置)。 下面显示了基本物种...
Create React App入门 该项目是通过引导的。 可用脚本 在项目目录中,可以运行: npm start 在开发模式下运行应用程序。 打开在浏览器中查看它。 如果您进行编辑,则页面将... 相反,它将所有配置文件和传递依赖项(w
可在此处找到JAR: : 特征可配置的产卵率可配置的死亡人数下降可配置的杀戮物品只在您想要的世界中生成它们可以在适当的时间冻结到位可配置的TARDIS密钥窃取信息哭泣的天使只在晚上成块地产卵。 他们带着灰色的...
FHIR中的罕见病计划 该存储库包含“ Eng PGO voor ... 从这些资源中生成FHIR配置文件。 基础是稀有条件的数据模型: 罕见病IS_A疾病,但也将由疾病组成:即Shwachman-Diamond综合征通常与中性粒细胞减少有关。 疾病
:diamond_with_a_dot: 主题 即将推出 :laptop: 命令行界面 了解更多。 :spiral_notepad: 配置 示例 。 在此处阅读文档。 前置功能 preonize函数当前是scss函数。 它使Preons可以在多个断点处生成大量规则,而...
java8 源码 在这个开源的时代,贡献一点点源代码,也许一名有点点追求的程序员必经的一个阶段, 本项目主要是想帮助那些初创电商项目...配置中心(Diamond/Apollo) Application Port App web dubbo blog-app 8083 2080