62,614
社区成员
发帖
与我相关
我的任务
分享
static {
Properties properties = loadPropertiesFile(path);
try {
druidDataSource = (DruidDataSource) DruidDataSourceFactory.createDataSource(properties); //DruidDataSrouce工厂模式
} catch (Exception e) {
log.error("获取配置失败");
}
}
private static Properties loadPropertiesFile(String fullFile) {
String webRootPath = null;
if (null == fullFile || fullFile.equals("")){
throw new IllegalArgumentException("Properties file path can not be null" + fullFile);
}
webRootPath = DBPoolConnection.class.getClassLoader().getResource("").getPath();
webRootPath = new File(webRootPath).getParent();
InputStream inputStream = null;
Properties p =null;
try {
inputStream = new FileInputStream(new File(webRootPath + File.separator + fullFile));
p = new Properties();
p.load(inputStream);
} catch (Exception e) {
e.printStackTrace();
} finally {
try {
if (null != inputStream){
inputStream.close();
}
} catch (Exception e) {
e.printStackTrace();
}
}
return p;
}