From deaadade97181707bb2953f2836e93bf4167a790 Mon Sep 17 00:00:00 2001 From: jinyu Date: Wed, 6 Jan 2016 22:05:51 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E5=A4=8Dweixin4j.properties=E6=96=87?= =?UTF-8?q?=E4=BB=B6=E4=B8=8D=E5=AD=98=E5=9C=A8=E6=97=B6=E6=8A=9B=E5=87=BA?= =?UTF-8?q?=E7=9A=84MissResourceException=E9=94=99=E8=AF=AF?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../weixin4j/util/Weixin4jConfigUtil.java | 36 +++++++++++-------- 1 file changed, 22 insertions(+), 14 deletions(-) diff --git a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/util/Weixin4jConfigUtil.java b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/util/Weixin4jConfigUtil.java index a424ae9f..c6e53da5 100644 --- a/weixin4j-base/src/main/java/com/foxinmy/weixin4j/util/Weixin4jConfigUtil.java +++ b/weixin4j-base/src/main/java/com/foxinmy/weixin4j/util/Weixin4jConfigUtil.java @@ -19,22 +19,26 @@ import com.foxinmy.weixin4j.model.WeixinAccount; public class Weixin4jConfigUtil { private final static String CLASSPATH_PREFIX = "classpath:"; private final static String CLASSPATH_VALUE; - private final static ResourceBundle weixinBundle; + private static ResourceBundle weixinBundle; static { - weixinBundle = ResourceBundle.getBundle("weixin4j"); - File file = null; CLASSPATH_VALUE = Thread.currentThread().getContextClassLoader() .getResource("").getPath(); - for (String key : weixinBundle.keySet()) { - if (!key.endsWith(".path")) { - continue; - } - file = new File(getValue(key).replaceFirst(CLASSPATH_PREFIX, - CLASSPATH_VALUE)); - if (!file.exists() && !file.mkdirs()) { - System.err.append(String.format("%s create fail.%n", - file.getAbsolutePath())); + try { + weixinBundle = ResourceBundle.getBundle("weixin4j"); + File file = null; + for (String key : weixinBundle.keySet()) { + if (!key.endsWith(".path")) { + continue; + } + file = new File(getValue(key).replaceFirst(CLASSPATH_PREFIX, + 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 { value = getValue(key); } catch (MissingResourceException e) { - System.err.println("'" + wrapKeyName(key) - + "' key not found in weixin4j.properties."); + ; + }catch (NullPointerException e){ + ; } return value; } @@ -99,6 +104,9 @@ public class Weixin4jConfigUtil { } public static WeixinAccount getWeixinAccount() { + if (weixinBundle == null) { + return null; + } WeixinAccount account = null; try { account = JSON