spring 加载jar包中的配置文件
package com.xxx.ssptsppt.dataexchange.utils; import com.xxx.maybee.engine.utils.FileUtil;
import com.xxx.maybee.engine.utils.PubString;
import org.springframework.core.io.Resource;
import org.springframework.core.io.support.PathMatchingResourcePatternResolver;
import org.springframework.core.io.support.ResourcePatternResolver; import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.util.HashMap;
import java.util.Map; public class Confs {
private static Map<String, File> confFiles; static {
confFiles = new HashMap<>();
String tmpDir = "tmpconf/";
ResourcePatternResolver resolver = new PathMatchingResourcePatternResolver();
try {
Resource[] resources = resolver.getResources("/*.json");
for (Resource resource : resources) {
String confName = resource.getFilename();
InputStream confIs = resource.getInputStream();
File confFile = extractFile(confName, confIs, tmpDir);
confFiles.put(confName, confFile);
}
} catch (IOException e) {
e.printStackTrace();
}
} private static File extractFile(String confName, InputStream confIs, String tmpDir) {
File tmpConfDir = new File(tmpDir);
if (!tmpConfDir.exists()) {
boolean mkdirs = tmpConfDir.mkdirs();
if (!mkdirs) {
throw new RuntimeException("临时配置文件无法创建!");
}
} File confFilePath = new File(tmpConfDir, confName);
try {
FileUtil.saveToFile(confIs, confFilePath, true, false);
} catch (IOException e) {
FileUtil.delFolder(tmpDir);
throw new RuntimeException("配置文件提取失败!");
} return confFilePath;
} public static File getConf(String confFileName) {
if (PubString.isNullOrSpace(confFileName)) {
return null;
}
return confFiles.get(confFileName);
}
}
spring 加载jar包中的配置文件的更多相关文章
- spring加载jar包中多个配置文件(转)
转自:http://evan0625.iteye.com/blog/1598366 在使用spring加载jar包中的配置文件时,不支持通配符,需要一个一个引入,如下所示: Java代码 <co ...
- spring加载jar包中多个配置文件
转自:http://www.cnblogs.com/GarfieldTom/p/3723915.html <import resource="classpath*:applicatio ...
- spring加载jar包中多个配置文件(转载)
本文转载自:http://www.cnblogs.com/GarfieldTom/p/3723915.html
- 动态加载jar包中的类(方式一)
嘛, 直接上代码 public static class TestClassLoader extends ClassLoader { @Override protected Class<?> ...
- idea中pom如何加载jar包依赖
1.需求分析 在特定需求的情况下,idea需要加载jar包,那么如何在idea中正确的配置jar依赖呢?今天博主就这个问题给大伙讲解下,希望对大伙有所帮助 2.实现方案①在工程src目录下新建l ...
- JAVA动态加载JAR包的实现
如何动态的加载这些驱动!不可能把所有的数据库驱动都集成到JAR包中吧?!于是动态加载驱动的JAR包就产生了!其实这些在做系统基础代码时,经常用到,只是一般我们没有机会去搞而已. 动态加载JAR包,使用 ...
- java动态加载jar包,并运行其中的类和方法
动态加载jar包,在实际开发中经常会需要用到,尤其涉及平台和业务的关系的时候,业务逻辑部分可以独立出去交给业务方管理,业务方只需要提供jar包,就能在平台上运行. 下面通过一个实例来直观演示: 第一: ...
- tomcat/Java指定加载jar包的路径
背景:部署的web站点,应用默认加载工程的/webapps/工程名/WEB-INF/lib下的jar包 但是我需要提供一个和web工程没关系的的jar包管理目录 解决方法: 执行java方法时 ...
- 动态加载jar包(二)
上次说的加载jar包,有几个问题没有解决: 1.如果项目包含了其他的jar包如何解决? 2.如何规范上传的jar包的类和方法? 下面就解决一下上面两个问题 一.首先编写被调用的类,这次使用maven工 ...
随机推荐
- android开发前奏曲之开发工具ADT
原文:http://android.eoe.cn/topic/android_sdk Android开发工具(ADT)插件为Eclipse提供了一个专业级的开发环境,用于构建Android应用程序.这 ...
- 模态推出 全屏 隐藏tabbar
SearchVC * vc = [[SearchVC alloc] init]; /* 底部向上 UIModalTransitionStyleCoverVertical // 淡入 UIMo ...
- Android:相机适配及图片处理的一些问题
链接:http://www.cnblogs.com/liushilin/p/6387263.html 链接:http://www.cnblogs.com/liushilin/p/5956691.htm ...
- PHP将CMYK颜色值和RGB颜色相互转换的例子
PHP将CMYK颜色值和RGB颜色相互转换的例子 function hex2rgb($hex) { $color = str_replace('#','',$hex); $rgb = array('r ...
- Atitit vue.js 把ajax数据 绑定到form表单
Atitit vue.js 把ajax数据 绑定到form表单 1.1. 使用场景:主要应用在编辑与提交场合..1 1.2. 绑定数据到form控件,可以使用jquery,不过vue.js更加简单1 ...
- 深入理解Linux内核-定时测量
定时测量:由基于固定频率振荡器和计数器的几个硬件电路完成的. 记时体系概貌: 内核中与时间相关的任务: 硬件设备: 实时时钟(RTC):1.Real Time Clock ,独立于CPU和所有芯片,每 ...
- Android4.42-Settings源代码分析之蓝牙模块Bluetooth总体实现(总)
本文为博主原创,转载请注明出处:http://blog.csdn.net/zrf1335348191/article/details/50995466 蓝牙相关代码已在另两篇文章中介绍,有须要的能够查 ...
- CCAction、CCFiniteTimeAction、CCSpeed、CCFollow
/**************************************************************************** Copyright (c) 2010-201 ...
- Why do people integrate Spark with TensorFlow even if there is a distributed TensorFlow framework?
https://www.quora.com/Why-do-people-integrate-Spark-with-TensorFlow-even-if-there-is-a-distributed-T ...
- linux命令(46):批量更改文件后缀,文件名
linux shell 1.要将所有 jpeg的后缀名图片文件修改为 jpg文件. rename .jpeg .jpg *.jpeg