1、读取 myconfig.properties 改为使用包装类,防止当key不存在时通过getString()获取值时抛出异常
This commit is contained in:
@@ -6,6 +6,7 @@ import java.util.concurrent.Future;
|
||||
|
||||
import nis.nms.util.BaseAction;
|
||||
import nis.nms.util.ConnectionOracle;
|
||||
import nis.nms.util.ResourceBundleWrapper;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.log4j.Logger;
|
||||
@@ -44,7 +45,7 @@ public class MailingManagerThread implements Runnable{
|
||||
}
|
||||
}
|
||||
|
||||
ResourceBundle rb = BaseAction.rb;
|
||||
ResourceBundleWrapper rb = BaseAction.rb;
|
||||
String address = rb.getString("email.address");
|
||||
String userName = rb.getString("email.userName");
|
||||
String password = rb.getString("email.password");
|
||||
|
||||
@@ -249,7 +249,7 @@ public abstract class BaseAction extends ActionSupport implements Serializable
|
||||
// private CommonService commonService;
|
||||
private static final long serialVersionUID = 7414962517552053966L;
|
||||
|
||||
public static ResourceBundle rb = ResourceBundle.getBundle("myconfig");
|
||||
public static ResourceBundleWrapper rb = new ResourceBundleWrapper(ResourceBundle.getBundle("myconfig"));
|
||||
|
||||
private String downLoadPath;//下载文件路径
|
||||
|
||||
@@ -1897,11 +1897,11 @@ public abstract class BaseAction extends ActionSupport implements Serializable
|
||||
public void setDownLoadPath(String downLoadPath) {
|
||||
this.downLoadPath = downLoadPath;
|
||||
}
|
||||
public static ResourceBundle getRb() {
|
||||
public static ResourceBundleWrapper getRb() {
|
||||
return rb;
|
||||
}
|
||||
public static void setRb(ResourceBundle rb) {
|
||||
BaseAction.rb = rb;
|
||||
BaseAction.rb = new ResourceBundleWrapper(rb);
|
||||
}
|
||||
|
||||
public String getPrevPageUrl() {
|
||||
|
||||
50
src/nis/nms/util/ResourceBundleWrapper.java
Normal file
50
src/nis/nms/util/ResourceBundleWrapper.java
Normal file
@@ -0,0 +1,50 @@
|
||||
package nis.nms.util;
|
||||
|
||||
import java.util.ResourceBundle;
|
||||
/**
|
||||
* ResourceBundle包装类
|
||||
* 解决:当配置文件没有key时抛出异常的的问题
|
||||
* @author fang
|
||||
*
|
||||
*/
|
||||
public class ResourceBundleWrapper {
|
||||
private ResourceBundle rb;
|
||||
public ResourceBundleWrapper(ResourceBundle rb) {
|
||||
this.rb = rb;
|
||||
}
|
||||
|
||||
/**
|
||||
* 当配置文件中没有配置key时,返回 null
|
||||
* @param key
|
||||
* @return
|
||||
*/
|
||||
public String getString(String key){
|
||||
return getString(key, null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 当配置文件中没有key时,返回 def 默认值
|
||||
* @param key
|
||||
* @param def
|
||||
* @return
|
||||
*/
|
||||
public String getString(String key,String def){
|
||||
if(rb.containsKey(key)){
|
||||
return rb.getString(key);
|
||||
}
|
||||
return def;
|
||||
}
|
||||
|
||||
|
||||
public boolean containsKey(String key){
|
||||
return rb.containsKey(key);
|
||||
}
|
||||
|
||||
public ResourceBundle getRb() {
|
||||
return rb;
|
||||
}
|
||||
public void setRb(ResourceBundle rb) {
|
||||
this.rb = rb;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user