From 18991c3f5b4e805b84cca688d5ab44f16796f593 Mon Sep 17 00:00:00 2001
From: xuxueli <931591021@qq.com>
Date: Fri, 26 Jan 2018 20:51:30 +0800
Subject: [PATCH] =?UTF-8?q?=E8=B0=83=E5=BA=A6=E4=B8=AD=E5=BF=83=E9=85=8D?=
=?UTF-8?q?=E7=BD=AE=E5=8A=A0=E8=BD=BD=E4=BC=98=E5=8C=96=EF=BC=8C=E5=8F=96?=
=?UTF-8?q?=E6=B6=88=E5=AF=B9=E9=85=8D=E7=BD=AE=E6=96=87=E4=BB=B6=E5=90=8D?=
=?UTF-8?q?=E7=9A=84=E5=BC=BA=E4=BE=9D=E8=B5=96=EF=BC=8C=E6=94=AF=E6=8C=81?=
=?UTF-8?q?=E5=8A=A0=E8=BD=BD=E7=A3=81=E7=9B=98=E9=85=8D=E7=BD=AE=EF=BC=9B?=
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
---
doc/XXL-JOB官方文档.md | 1 +
.../interceptor/PermissionInterceptor.java | 6 +-
.../admin/core/conf/XxlJobAdminConfig.java | 81 +++++++++++++++++++
.../com/xxl/job/admin/core/util/I18nUtil.java | 9 +--
.../com/xxl/job/admin/core/util/MailUtil.java | 22 ++---
.../job/admin/core/util/PropertiesUtil.java | 38 ---------
.../spring/applicationcontext-base.xml | 2 +-
.../controller/JobInfoControllerTest.java | 6 +-
.../com/xxl/job/admin/util/I18nUtilTest.java | 5 ++
.../com/xxl/job/admin/util/MailUtilTest.java | 5 ++
.../job/admin/util/PropertiesUtilTest.java | 18 -----
11 files changed, 108 insertions(+), 85 deletions(-)
create mode 100644 xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java
delete mode 100644 xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/PropertiesUtil.java
delete mode 100644 xxl-job-admin/src/test/java/com/xxl/job/admin/util/PropertiesUtilTest.java
diff --git a/doc/XXL-JOB官方文档.md b/doc/XXL-JOB官方文档.md
index 2e5d5bfa..0130d2f6 100644
--- a/doc/XXL-JOB官方文档.md
+++ b/doc/XXL-JOB官方文档.md
@@ -1146,6 +1146,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 3、调度报表优化,报表SQL调优并且新增LocalCache缓存(缓存时间60s),提高大数据量下报表加载速度;
- 4、修复打包部署时资源文件乱码问题;
- 5、修复新版本chrome滚动到顶部失效问题;
+- 6、调度中心配置加载优化,取消对配置文件名的强依赖,支持加载磁盘配置;
### TODO LIST
diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/interceptor/PermissionInterceptor.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/interceptor/PermissionInterceptor.java
index 1d6facf5..b72cf99e 100644
--- a/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/interceptor/PermissionInterceptor.java
+++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/controller/interceptor/PermissionInterceptor.java
@@ -1,8 +1,8 @@
package com.xxl.job.admin.controller.interceptor;
import com.xxl.job.admin.controller.annotation.PermessionLimit;
+import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
import com.xxl.job.admin.core.util.CookieUtil;
-import com.xxl.job.admin.core.util.PropertiesUtil;
import org.apache.commons.codec.digest.DigestUtils;
import org.springframework.web.method.HandlerMethod;
import org.springframework.web.servlet.handler.HandlerInterceptorAdapter;
@@ -22,8 +22,8 @@ public class PermissionInterceptor extends HandlerInterceptorAdapter {
public static final String LOGIN_IDENTITY_KEY = "XXL_JOB_LOGIN_IDENTITY";
public static final String LOGIN_IDENTITY_TOKEN;
static {
- String username = PropertiesUtil.getString("xxl.job.login.username");
- String password = PropertiesUtil.getString("xxl.job.login.password");
+ String username = XxlJobAdminConfig.getAdminConfig().getLoginUsername();
+ String password = XxlJobAdminConfig.getAdminConfig().getLoginPassword();
// login token
String tokenTmp = DigestUtils.md5Hex(username + "_" + password);
diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java
new file mode 100644
index 00000000..adcd321c
--- /dev/null
+++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/conf/XxlJobAdminConfig.java
@@ -0,0 +1,81 @@
+package com.xxl.job.admin.core.conf;
+
+import org.springframework.beans.factory.InitializingBean;
+import org.springframework.beans.factory.annotation.Value;
+import org.springframework.context.annotation.Configuration;
+
+/**
+ * xxl-job config
+ *
+ * @author xuxueli 2017-04-28
+ */
+@Configuration
+public class XxlJobAdminConfig implements InitializingBean{
+ private static XxlJobAdminConfig adminConfig = null;
+ public static XxlJobAdminConfig getAdminConfig() {
+ return adminConfig;
+ }
+
+ @Override
+ public void afterPropertiesSet() throws Exception {
+ adminConfig = this;
+ }
+
+ @Value("${xxl.job.mail.host}")
+ private String mailHost;
+
+ @Value("${xxl.job.mail.port}")
+ private String mailPort;
+
+ @Value("${xxl.job.mail.username}")
+ private String mailUsername;
+
+ @Value("${xxl.job.mail.password}")
+ private String mailPassword;
+
+ @Value("${xxl.job.mail.sendNick}")
+ private String mailSendNick;
+
+ @Value("${xxl.job.login.username}")
+ private String loginUsername;
+
+ @Value("${xxl.job.login.password}")
+ private String loginPassword;
+
+ @Value("${xxl.job.i18n}")
+ private String i18n;
+
+
+ public String getMailHost() {
+ return mailHost;
+ }
+
+ public String getMailPort() {
+ return mailPort;
+ }
+
+ public String getMailUsername() {
+ return mailUsername;
+ }
+
+ public String getMailPassword() {
+ return mailPassword;
+ }
+
+ public String getMailSendNick() {
+ return mailSendNick;
+ }
+
+ public String getLoginUsername() {
+ return loginUsername;
+ }
+
+ public String getLoginPassword() {
+ return loginPassword;
+ }
+
+ public String getI18n() {
+ return i18n;
+ }
+
+}
diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/I18nUtil.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/I18nUtil.java
index 2330a44f..93b255c9 100644
--- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/I18nUtil.java
+++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/I18nUtil.java
@@ -1,5 +1,6 @@
package com.xxl.job.admin.core.util;
+import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
import com.xxl.job.core.util.JacksonUtil;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
@@ -23,23 +24,21 @@ import java.util.Properties;
public class I18nUtil {
private static Logger logger = LoggerFactory.getLogger(I18nUtil.class);
- private static final String I18N_PROP_CACHE = "i18n_prop_cache";
+ private static Properties prop = null;
public static Properties loadI18nProp(){
- Properties prop = (Properties) LocalCacheUtil.get(I18N_PROP_CACHE);
if (prop != null) {
return prop;
}
try {
// bild i18n prop
- String i18n = PropertiesUtil.getString("xxl.job.i18n");
+ String i18n = XxlJobAdminConfig.getAdminConfig().getI18n();
i18n = StringUtils.isNotBlank(i18n)?("_"+i18n):i18n;
- String i18nFile =MessageFormat.format("i18n/message{0}.properties", i18n);
+ String i18nFile = MessageFormat.format("i18n/message{0}.properties", i18n);
// load prop
Resource resource = new ClassPathResource(i18nFile);
EncodedResource encodedResource = new EncodedResource(resource,"UTF-8");
prop = PropertiesLoaderUtils.loadProperties(encodedResource);
- LocalCacheUtil.set(I18N_PROP_CACHE, prop, 60*1000); // cache 60s
} catch (IOException e) {
logger.error(e.getMessage(), e);
}
diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/MailUtil.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/MailUtil.java
index e000b157..8e469bc7 100644
--- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/MailUtil.java
+++ b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/MailUtil.java
@@ -1,5 +1,6 @@
package com.xxl.job.admin.core.util;
+import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
import org.apache.commons.mail.DefaultAuthenticator;
import org.apache.commons.mail.EmailException;
import org.apache.commons.mail.HtmlEmail;
@@ -16,19 +17,6 @@ import java.nio.charset.Charset;
public class MailUtil {
private static Logger logger = LoggerFactory.getLogger(MailUtil.class);
- private static String host;
- private static String port;
- private static String username;
- private static String password;
- private static String sendNick;
- static{
- host = PropertiesUtil.getString("xxl.job.mail.host");
- port = PropertiesUtil.getString("xxl.job.mail.port");
- username = PropertiesUtil.getString("xxl.job.mail.username");
- password = PropertiesUtil.getString("xxl.job.mail.password");
- sendNick = PropertiesUtil.getString("xxl.job.mail.sendNick");
- }
-
/**
*
* @param toAddress 收件人邮箱
@@ -46,13 +34,13 @@ public class MailUtil {
//email.setTLS(true); // 是否TLS校验,,某些邮箱需要TLS安全校验,同理有SSL校验
//email.setSSL(true);
- email.setHostName(host);
- email.setSmtpPort(Integer.valueOf(port));
+ email.setHostName(XxlJobAdminConfig.getAdminConfig().getMailHost());
+ email.setSmtpPort(Integer.valueOf(XxlJobAdminConfig.getAdminConfig().getMailPort()));
//email.setSslSmtpPort(port);
- email.setAuthenticator(new DefaultAuthenticator(username, password));
+ email.setAuthenticator(new DefaultAuthenticator(XxlJobAdminConfig.getAdminConfig().getMailUsername(), XxlJobAdminConfig.getAdminConfig().getMailPassword()));
email.setCharset(Charset.defaultCharset().name());
- email.setFrom(username, sendNick);
+ email.setFrom(XxlJobAdminConfig.getAdminConfig().getMailUsername(), XxlJobAdminConfig.getAdminConfig().getMailSendNick());
email.addTo(toAddress);
email.setSubject(mailSubject);
email.setMsg(mailBody);
diff --git a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/PropertiesUtil.java b/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/PropertiesUtil.java
deleted file mode 100644
index a3c60077..00000000
--- a/xxl-job-admin/src/main/java/com/xxl/job/admin/core/util/PropertiesUtil.java
+++ /dev/null
@@ -1,38 +0,0 @@
-package com.xxl.job.admin.core.util;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.Resource;
-import org.springframework.core.io.support.EncodedResource;
-import org.springframework.core.io.support.PropertiesLoaderUtils;
-
-import java.io.IOException;
-import java.util.Properties;
-
-/**
- * properties util
- *
- * @author xuxueli 2015-8-28 10:35:53
- */
-public class PropertiesUtil {
- private static Logger logger = LoggerFactory.getLogger(PropertiesUtil.class);
- private static final String file_name = "xxl-job-admin.properties";
-
-
- public static String getString(String key) {
- Properties prop = null;
- try {
- Resource resource = new ClassPathResource(file_name);
- EncodedResource encodedResource = new EncodedResource(resource,"UTF-8");
- prop = PropertiesLoaderUtils.loadProperties(encodedResource);
- } catch (IOException e) {
- logger.error(e.getMessage(), e);
- }
- if (prop!=null) {
- return prop.getProperty(key);
- }
- return null;
- }
-
-}
diff --git a/xxl-job-admin/src/main/resources/spring/applicationcontext-base.xml b/xxl-job-admin/src/main/resources/spring/applicationcontext-base.xml
index af486d7d..003649cf 100644
--- a/xxl-job-admin/src/main/resources/spring/applicationcontext-base.xml
+++ b/xxl-job-admin/src/main/resources/spring/applicationcontext-base.xml
@@ -7,7 +7,7 @@
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
-
+
diff --git a/xxl-job-admin/src/test/java/com/xxl/job/admin/controller/JobInfoControllerTest.java b/xxl-job-admin/src/test/java/com/xxl/job/admin/controller/JobInfoControllerTest.java
index 8da5fda3..2a1a418e 100644
--- a/xxl-job-admin/src/test/java/com/xxl/job/admin/controller/JobInfoControllerTest.java
+++ b/xxl-job-admin/src/test/java/com/xxl/job/admin/controller/JobInfoControllerTest.java
@@ -1,7 +1,7 @@
package com.xxl.job.admin.controller;
import com.xxl.job.admin.controller.interceptor.PermissionInterceptor;
-import com.xxl.job.admin.core.util.PropertiesUtil;
+import com.xxl.job.admin.core.conf.XxlJobAdminConfig;
import org.junit.Before;
import org.junit.Test;
import org.springframework.http.MediaType;
@@ -22,8 +22,8 @@ public class JobInfoControllerTest extends AbstractSpringMvcTest {
MvcResult ret = mockMvc.perform(
post("/login")
.contentType(MediaType.APPLICATION_FORM_URLENCODED)
- .param("userName", PropertiesUtil.getString("xxl.job.login.username"))
- .param("password", PropertiesUtil.getString("xxl.job.login.password"))
+ .param("userName", XxlJobAdminConfig.getAdminConfig().getLoginUsername())
+ .param("password", XxlJobAdminConfig.getAdminConfig().getLoginPassword())
).andReturn();
cookie = ret.getResponse().getCookie(PermissionInterceptor.LOGIN_IDENTITY_KEY);
}
diff --git a/xxl-job-admin/src/test/java/com/xxl/job/admin/util/I18nUtilTest.java b/xxl-job-admin/src/test/java/com/xxl/job/admin/util/I18nUtilTest.java
index c0d6dd33..0d03790e 100644
--- a/xxl-job-admin/src/test/java/com/xxl/job/admin/util/I18nUtilTest.java
+++ b/xxl-job-admin/src/test/java/com/xxl/job/admin/util/I18nUtilTest.java
@@ -2,12 +2,17 @@ package com.xxl.job.admin.util;
import com.xxl.job.admin.core.util.I18nUtil;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
/**
* email util test
*
* @author xuxueli 2017-12-22 17:16:23
*/
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = "classpath*:spring/applicationcontext-*.xml")
public class I18nUtilTest {
@Test
diff --git a/xxl-job-admin/src/test/java/com/xxl/job/admin/util/MailUtilTest.java b/xxl-job-admin/src/test/java/com/xxl/job/admin/util/MailUtilTest.java
index 3821818b..a800421e 100644
--- a/xxl-job-admin/src/test/java/com/xxl/job/admin/util/MailUtilTest.java
+++ b/xxl-job-admin/src/test/java/com/xxl/job/admin/util/MailUtilTest.java
@@ -2,6 +2,9 @@ package com.xxl.job.admin.util;
import com.xxl.job.admin.core.util.MailUtil;
import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.springframework.test.context.ContextConfiguration;
+import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import java.text.MessageFormat;
@@ -10,6 +13,8 @@ import java.text.MessageFormat;
*
* @author xuxueli 2017-12-22 17:16:23
*/
+@RunWith(SpringJUnit4ClassRunner.class)
+@ContextConfiguration(locations = "classpath*:spring/applicationcontext-*.xml")
public class MailUtilTest {
@Test
diff --git a/xxl-job-admin/src/test/java/com/xxl/job/admin/util/PropertiesUtilTest.java b/xxl-job-admin/src/test/java/com/xxl/job/admin/util/PropertiesUtilTest.java
deleted file mode 100644
index 5c8b7f04..00000000
--- a/xxl-job-admin/src/test/java/com/xxl/job/admin/util/PropertiesUtilTest.java
+++ /dev/null
@@ -1,18 +0,0 @@
-package com.xxl.job.admin.util;
-
-import com.xxl.job.admin.core.util.PropertiesUtil;
-import org.junit.Test;
-
-/**
- * prop util test
- *
- * @author xuxueli 2017-12-25 15:17:36
- */
-public class PropertiesUtilTest {
-
- @Test
- public void registryTest() throws Exception {
- System.out.println(PropertiesUtil.getString("xxl.job.login.username"));
- }
-
-}