修复weixin4j.properties文件不存在时抛出的MissResourceException错误
This commit is contained in:
parent
5c212907fa
commit
deaadade97
@ -19,22 +19,26 @@ import com.foxinmy.weixin4j.model.WeixinAccount;
|
|||||||
public class Weixin4jConfigUtil {
|
public class Weixin4jConfigUtil {
|
||||||
private final static String CLASSPATH_PREFIX = "classpath:";
|
private final static String CLASSPATH_PREFIX = "classpath:";
|
||||||
private final static String CLASSPATH_VALUE;
|
private final static String CLASSPATH_VALUE;
|
||||||
private final static ResourceBundle weixinBundle;
|
private static ResourceBundle weixinBundle;
|
||||||
static {
|
static {
|
||||||
weixinBundle = ResourceBundle.getBundle("weixin4j");
|
|
||||||
File file = null;
|
|
||||||
CLASSPATH_VALUE = Thread.currentThread().getContextClassLoader()
|
CLASSPATH_VALUE = Thread.currentThread().getContextClassLoader()
|
||||||
.getResource("").getPath();
|
.getResource("").getPath();
|
||||||
for (String key : weixinBundle.keySet()) {
|
try {
|
||||||
if (!key.endsWith(".path")) {
|
weixinBundle = ResourceBundle.getBundle("weixin4j");
|
||||||
continue;
|
File file = null;
|
||||||
}
|
for (String key : weixinBundle.keySet()) {
|
||||||
file = new File(getValue(key).replaceFirst(CLASSPATH_PREFIX,
|
if (!key.endsWith(".path")) {
|
||||||
CLASSPATH_VALUE));
|
continue;
|
||||||
if (!file.exists() && !file.mkdirs()) {
|
}
|
||||||
System.err.append(String.format("%s create fail.%n",
|
file = new File(getValue(key).replaceFirst(CLASSPATH_PREFIX,
|
||||||
file.getAbsolutePath()));
|
CLASSPATH_VALUE));
|
||||||
|
if (!file.exists() && !file.mkdirs()) {
|
||||||
|
System.err.append(String.format("%s create fail.%n",
|
||||||
|
file.getAbsolutePath()));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
} catch (MissingResourceException e) {
|
||||||
|
;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -70,8 +74,9 @@ public class Weixin4jConfigUtil {
|
|||||||
try {
|
try {
|
||||||
value = getValue(key);
|
value = getValue(key);
|
||||||
} catch (MissingResourceException e) {
|
} catch (MissingResourceException e) {
|
||||||
System.err.println("'" + wrapKeyName(key)
|
;
|
||||||
+ "' key not found in weixin4j.properties.");
|
}catch (NullPointerException e){
|
||||||
|
;
|
||||||
}
|
}
|
||||||
return value;
|
return value;
|
||||||
}
|
}
|
||||||
@ -99,6 +104,9 @@ public class Weixin4jConfigUtil {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public static WeixinAccount getWeixinAccount() {
|
public static WeixinAccount getWeixinAccount() {
|
||||||
|
if (weixinBundle == null) {
|
||||||
|
return null;
|
||||||
|
}
|
||||||
WeixinAccount account = null;
|
WeixinAccount account = null;
|
||||||
try {
|
try {
|
||||||
account = JSON
|
account = JSON
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user