调度中心配置加载优化,取消对配置文件名的强依赖,支持加载磁盘配置;

pull/6/head
xuxueli 7 years ago
parent dbf51a03ba
commit 18991c3f5b

@ -1146,6 +1146,7 @@ Tips: 历史版本(V1.3.x)目前已经Release至稳定版本, 进入维护阶段
- 3、调度报表优化报表SQL调优并且新增LocalCache缓存缓存时间60s提高大数据量下报表加载速度
- 4、修复打包部署时资源文件乱码问题
- 5、修复新版本chrome滚动到顶部失效问题
- 6、调度中心配置加载优化取消对配置文件名的强依赖支持加载磁盘配置
### TODO LIST

@ -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);

@ -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;
}
}

@ -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,15 +24,14 @@ 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);
@ -39,7 +39,6 @@ public class I18nUtil {
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);
}

@ -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);

@ -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;
}
}

@ -7,7 +7,7 @@
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context.xsd">
<context:component-scan base-package="com.xxl.job.admin.service, com.xxl.job.admin.dao" />
<context:component-scan base-package="com.xxl.job.admin.core.conf, com.xxl.job.admin.service, com.xxl.job.admin.dao" />
<bean id="freemarkerConfig" class="org.springframework.web.servlet.view.freemarker.FreeMarkerConfigurer">
<property name="templateLoaderPath" value="/WEB-INF/template/" />

@ -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);
}

@ -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

@ -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

@ -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"));
}
}
Loading…
Cancel
Save