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包中的配置文件的更多相关文章

  1. spring加载jar包中多个配置文件(转)

    转自:http://evan0625.iteye.com/blog/1598366 在使用spring加载jar包中的配置文件时,不支持通配符,需要一个一个引入,如下所示: Java代码 <co ...

  2. spring加载jar包中多个配置文件

    转自:http://www.cnblogs.com/GarfieldTom/p/3723915.html <import resource="classpath*:applicatio ...

  3. spring加载jar包中多个配置文件(转载)

    本文转载自:http://www.cnblogs.com/GarfieldTom/p/3723915.html

  4. 动态加载jar包中的类(方式一)

    嘛, 直接上代码 public static class TestClassLoader extends ClassLoader { @Override protected Class<?> ...

  5. idea中pom如何加载jar包依赖

    1.需求分析    在特定需求的情况下,idea需要加载jar包,那么如何在idea中正确的配置jar依赖呢?今天博主就这个问题给大伙讲解下,希望对大伙有所帮助 2.实现方案①在工程src目录下新建l ...

  6. JAVA动态加载JAR包的实现

    如何动态的加载这些驱动!不可能把所有的数据库驱动都集成到JAR包中吧?!于是动态加载驱动的JAR包就产生了!其实这些在做系统基础代码时,经常用到,只是一般我们没有机会去搞而已. 动态加载JAR包,使用 ...

  7. java动态加载jar包,并运行其中的类和方法

    动态加载jar包,在实际开发中经常会需要用到,尤其涉及平台和业务的关系的时候,业务逻辑部分可以独立出去交给业务方管理,业务方只需要提供jar包,就能在平台上运行. 下面通过一个实例来直观演示: 第一: ...

  8. tomcat/Java指定加载jar包的路径

    背景:部署的web站点,应用默认加载工程的/webapps/工程名/WEB-INF/lib下的jar包   但是我需要提供一个和web工程没关系的的jar包管理目录   解决方法: 执行java方法时 ...

  9. 动态加载jar包(二)

    上次说的加载jar包,有几个问题没有解决: 1.如果项目包含了其他的jar包如何解决? 2.如何规范上传的jar包的类和方法? 下面就解决一下上面两个问题 一.首先编写被调用的类,这次使用maven工 ...

随机推荐

  1. MetInfo PHP的CMS,目测还不错

    MetInfo PHP的CMS,目测还不错,先记录下来

  2. CSS边框闪烁呼吸样式

    <html> <body> <head> .arrow_box{animation: glow 800ms ease-out infinite alternate; ...

  3. ASP.NET MVC做的微信WEBAPP中调用微信JSSDK扫一扫

    今天做一个项目,是在微信上用的,微信WEB APP,里面用到了调用手机摄像头扫一扫二维码的功能,记得以前某个项目里写有的,但是找不到之前那个项目源码了,想复制粘贴也复制不了了,只好对着微信的那个开发文 ...

  4. Atitti cto的日常流程与职责attilax总结

    Atitti cto的日常流程与职责attilax总结 1. (最重要)技术战略制定 规划,预测趋势1 1.1. 关键词 Throught技术雷达 趋势 没落  已死  辉煌 未来1 1.2. (比较 ...

  5. redisHelper

    using System; using System.Collections.Generic; using System.Linq; using System.Text; using ServiceS ...

  6. UML的通用机制(三)

     Common Divisions In modeling object-oriented systems, the world often gets divided in several way ...

  7. kvm 给虚机增加网卡

    [root@666 ok]# virsh domiflist c03 Interface Type Source Model MAC --------------------------------- ...

  8. tomcat最大并发连接数的修改方法

    转载:http://blog.csdn.net/qysh123/article/details/11678903 这是个很简单的问题,但是搜了一圈,发现大家都写错了.所以这里总结一下: 几乎所有的中文 ...

  9. MVC+EF+PagedList+调用通用存储封装+多表联合信息展示分页+存储过程分页

    主要的技术点不在这里一一阐述,相关存储也是引用别人的,主要技术点就是通过最优性能方式处理需求,PagedList.包需要在线安装就可以 直接上干货 1.存储代码之第一种: 参数相对多点 /**//* ...

  10. 每日英语:Singles Day in China

    Singles Day in China is the celebration -- or mourning -- of being unattached. Started by students i ...