import java.io.File;
import java.io.FileInputStream;
import java.net.URL;
import java.util.Map; import org.bouncycastle.crypto.RuntimeCryptoException;
import org.yaml.snakeyaml.Yaml; public class DbpTestConfig {
private static String dbpIP; private static String dbpPort; private static String testServerIP; private static String testServerPort; static{
Yaml yaml = new Yaml();
try {
        //读取当前项目同级目录下的配置文件,jar包形式
File dumpFile=new File(System.getProperty("user.dir") + "/application.yml");
if(!dumpFile.exists()){
          //读取source目录下配置文件
URL url = DbpTestConfig.class.getClassLoader().getResource("application.yml");
if(url==null){
throw new RuntimeException("not found application.yml");
}
dumpFile=new File(url.getPath());
} Map map =(Map)yaml.load(new FileInputStream(dumpFile));
Map<String,String> paramMap =(Map) map.get("dbptest");
if(paramMap==null){
throw new RuntimeException("not found parameter dbptest");
}
dbpIP=paramMap.get("dbpIP");
dbpPort=String.valueOf(paramMap.get("dbpPort"));
testServerIP=paramMap.get("testServerIP");
testServerPort=String.valueOf(paramMap.get("testServerPort")); } catch (Exception e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
} public static String getDbpIP() {
return dbpIP;
} public static String getDbpPort() {
return dbpPort;
} public static String getTestServerIP() {
return testServerIP;
} public static String getTestServerPort() {
return testServerPort;
} }

java 读取外部和source下配置文件的更多相关文章

  1. java读取某个文件夹下的所有文件

    import java.io.FileNotFoundException;import java.io.IOException;import java.io.File; public class Re ...

  2. linux共享文件samba安装与java读取外部文件夹方法

    测试环境RedHat 6.4 一.安装 samba组件安装: (1)首先用“rpm –qa |grep samba”命令检验系统samba服务是否安装. #rpm –qa |grep samba sa ...

  3. SpringBoot学习(三)-->Spring的Java配置方式之读取外部的资源配置文件并配置数据库连接池

    三.读取外部的资源配置文件并配置数据库连接池 1.读取外部的资源配置文件 通过@PropertySource可以指定读取的配置文件,通过@Value注解获取值,具体用法: @Configuration ...

  4. java读取resource目录下的配置文件

    java读取resource目录下的配置文件 1:配置resource目录 下的文件 host: 127.0.0.1 port: 9300 2:读取    / 代表resource目录 InputSt ...

  5. Java读取Maven工程下的配置文件,工具类

    Java开发中,经常需要在maven工程中读取src/main/resources下的配置文件: 思路如下: Class.getClassLoader() 返回类加载器ClassLoader,进而可以 ...

  6. java 读取src下的配置文件

    很多时候,我们都将配置文件放在eclipse的src目录下,这个位置,相当于,当导出可执行jar包后,配置文件放在和jar同级的目录中,比如jar包放在/opt目录下,则配置文件放在/opt下,则ja ...

  7. spark读取外部配置文件的方法

    spark读取外部配置文件的方法 spark-submit  --files /tmp/fileName /tmp/test.jar 使用spark提交时使用--files参数,spark会将将本地的 ...

  8. java读取properties配置文件总结

    java读取properties配置文件总结 在日常项目开发和学习中,我们不免会经常用到.propeties配置文件,例如数据库c3p0连接池的配置等.而我们经常读取配置文件的方法有以下两种: (1) ...

  9. jar包读取jar包内部和外部的配置文件,springboot读取外部配置文件的方法

    jar包读取jar包内部和外部的配置文件,springboot读取外部配置文件的方法 用系统属性System.getProperty("user.dir")获得执行命令的目录(网上 ...

随机推荐

  1. SharePoint 2013 新特性 (三) 破改式 —— 设计管理器的使用 [1.设备通道]

    首先,哥们儿们会问,为啥要有设计管理器呢,不是原来就可以编辑页面了么,原来那个编辑不了模板页和布局页,也不能打包,而且也看不到具体HTML代码,不能编辑CSS,当然,你安装的SharePoint De ...

  2. Spring源码学习笔记2

    1.默认标签的解析 对四种不同标签的解析 private void parseDefaultElement(Element ele, BeanDefinitionParserDelegate dele ...

  3. s21day17 python笔记

    s21day17 python笔记 一.内容回顾及补充 回顾 补充 第三方模块补充 需要下载安装后才能导入使用 安装方式: pip包管理工具 # 把pip.exe 所在的目录添加到环境变量中. pip ...

  4. 设计一个字符串类String(C++练习题)

    要求:设计一个字符串类String,可以求字符串长度,可以连接两个串(如,s1=“计算机”,s2=“软件”,s1与s2连接得到“计算机软件”),并且重载“=”运算符进行字符串赋值,编写主程序实现:s1 ...

  5. oracle数据库连接缓慢

    今天连接数据库时非常的慢,大概将近1分钟,才能连上,感觉不对,登录数据库所在的服务器,进行检查,常规的内存.硬盘.CPU全都正常,然后想要进入oracle用户时报错了:su: cannot set u ...

  6. linux下lampp的启动和停止脚本

    今天试着写了lampp的启动停止脚本,和上一篇的tomcat的启动停止有一点小区别,就是lampp启动之后有很多的进程号,如果按照tomcat的停止脚本写就会出错,下面做细细的介绍 1.lampp的停 ...

  7. C# Cookie方法

    //写入 protected void Button1_Click(object sender, EventArgs e) { HttpCookie cookie=new HttpCookie(&qu ...

  8. @EnableScheduling注解

    @EnableScheduling 开启对定时任务的支持       其中Scheduled注解中有以下几个参数: 1.cron是设置定时执行的表达式,如 0 0/5 * * * ?每隔五分钟执行一次 ...

  9. vue day5 分页控件

    <!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content ...

  10. 2_PY基本数据类型

    python的数据类型和R差不多,但是需要注意的是字符访问方式与R不一样,另外,python中的“真”和“假”是True False(首字母大写). 1.字符串 字符串和R的定义差不多比如: data ...