读取config配置信息

//config.properties中配置了数据库配置的相关信息,通过这个单例模式设计来实现解耦。
public class PathConfig {
	private static PathConfig instance = null;
	private String dataPath = null;
	private PathConfig(){
		InputStream in = getClass().getResourceAsStream("/config.properties");
		Properties p = new Properties();
		try {
			p.load(in);
			url = p.getProperty("DBURL", "");
                        username = p.getProperty("DBUSER", "");
                        password = p.getProperty("DBPASS", "");
                }catch(IOException e){
                        e.printStackTrace();
                }
      }
      public static synchronized PathConfig getInstance(){
               if(instance == null){
                    instance = new PathConfig();
               }
               return instance;
     }
}

config.properties:

DBURL=jdbc:oracle:thin:@xxx.xxx.x.x:1521:XE
DBUSER=xxxxx
DBPASS=xxxxx
时间: 2024-08-06 21:11:06

读取config配置信息的相关文章

golang 读取 ini配置信息

package main //BY: [email protected]//这个有一定问题   如果配置信息里有中文就不行//[Server] ;MYSQL配置//Server=localhost   ;主机//golang 读取 ini配置信息//http://www.widuu.com/archives/02/961.htmlimport (  "fmt"  "github.com/widuu/goini"  //"runtime"  //&

spring读取加密配置信息

描述&背景Spring框架配置数据库等连接等属性时,都是交由 PopertyPlaceholderConfigurer进行读取.properties文件的,但如果项目不允许在配置文件中明文保存密码等重要的连接信息,此时,唯有继承PopertyPlaceholderConfigurer,并重写convertProperty(String propertyName, String propertyValue)方法,该方法是java中少有的传参承载设计模式,在这里,我们可以拿到我们需要进行解密的密文再

读取.properties配置信息

package com.ctcti.webcallcenter.utils; import java.io.FileInputStream;import java.io.FileNotFoundException;import java.io.FileOutputStream;import java.io.IOException;import java.io.InputStream;import java.io.OutputStream;import java.util.Enumeration;

wdmWin10下读取PCI配置信息

WDM下HalGetBusData不能用了.加上感觉png方式太麻烦.自己修改了驱动开发技术详解上的代码直接在驱动下获取信息 #include "Driver.h" NTSTATUS DriverEntry( IN PDRIVER_OBJECT pDriverObject, IN PUNICODE_STRING pRegistryPath) { NTSTATUS status; //判断CPU类型 CPUType(); //枚举 EnumeratePCI(); KdPrint((&qu

ASP.NET添加、修改、删除web.config配置信息

1.导入命名空间? using System.Configuration; using System.Web.Configuration ; 2.输入代码? protected void Page_Load(object sender, EventArgs e) { if (!Page.IsPostBack) { //保存在配置文件中 TextBox1.Text= WebConfigurationManager.AppSettings["xdsj"].ToString(); TextB

使用Spring读取xml文件中的配置信息

一般写程序时我们都会将一些配置信息写到配置文件中,以便在不修改源码的情况下对程序的某些点进行更改.这里介绍一种Spring读取xml配置文件的方式,其基本思路如下:定义一个java类,其中定义一些静态变量对应我们的配置信息,然后采用注入的方式将变量值初始化为配置值.示例代码如下: 新建一个java类: package java; public class Config { //要配置的值 public static int value = 0; //这里不能写成静态的 public void s

教你如何利用分布式的思想处理集群的参数配置信息——spring的configurer妙用

引言 最近LZ的技术博文数量直线下降,实在是非常抱歉,之前LZ曾信誓旦旦的说一定要把<深入理解计算机系统>写完,现在看来,LZ似乎是在打自己脸了.尽管LZ内心一直没放弃,但从现状来看,需要等LZ的PM做的比较稳定,时间慢慢空闲出来的时候才有机会看了.短时间内,还是要以解决实际问题为主,而不是增加自己其它方面的实力. 因此,本着解决实际问题的目的,LZ就研究出一种解决当下问题的方案,可能文章的标题看起来挺牛B的,其实LZ就是简单的利用了一下分布式的思想,以及spring框架的特性,解决了当下的参

igmpproxy源代码学习——配置信息加载

在igmpproxy主程序运行之前需要先读取配置文件,igmpproxy的配置文件通常为/etc/igmpproxy.conf或者/var/igmpproxy.conf 其内容如下: quickleave mode 3 phyint ppp0 upstream ratelimit 0 threshold 1 phyint br0 downstream ratelimit 0 threshold 1 igmpproxy加载配置文件信息由main函数中调用loadConfig()实现,加载配置文件的

配置信息

<?xml version="1.0"?> <configuration> <configSections> <section name="log4net" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" /> </configSections> <log4net> <root>