mirror of https://github.com/elunez/eladmin
Merge branch 'master' of https://github.com/elunez/eladmin
# Conflicts: # eladmin-common/src/main/java/me/zhengjie/utils/CallBack.java # eladmin-common/src/main/java/me/zhengjie/utils/FileUtil.java # eladmin-common/src/main/java/me/zhengjie/utils/SpringContextHolder.java # eladmin-common/src/main/java/me/zhengjie/utils/StringUtils.javapull/403/head
commit
9b8b01c55c
|
@ -16,8 +16,6 @@
|
||||||
|
|
||||||
package me.zhengjie.utils;
|
package me.zhengjie.utils;
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author: liaojinlong
|
* @author: liaojinlong
|
||||||
* @date: 2020/6/9 17:02
|
* @date: 2020/6/9 17:02
|
||||||
|
@ -36,8 +34,7 @@ public interface CallBack {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 本回调任务名称
|
* 本回调任务名称
|
||||||
*
|
* @return /
|
||||||
* @return
|
|
||||||
*/
|
*/
|
||||||
default String getCallBackName() {
|
default String getCallBackName() {
|
||||||
return Thread.currentThread().getId() + ":" + this.getClass().getName();
|
return Thread.currentThread().getId() + ":" + this.getClass().getName();
|
||||||
|
|
|
@ -21,7 +21,6 @@ import org.springframework.beans.factory.DisposableBean;
|
||||||
import org.springframework.context.ApplicationContext;
|
import org.springframework.context.ApplicationContext;
|
||||||
import org.springframework.context.ApplicationContextAware;
|
import org.springframework.context.ApplicationContextAware;
|
||||||
import org.springframework.core.env.Environment;
|
import org.springframework.core.env.Environment;
|
||||||
|
|
||||||
import java.util.ArrayList;
|
import java.util.ArrayList;
|
||||||
import java.util.List;
|
import java.util.List;
|
||||||
|
|
||||||
|
@ -33,7 +32,7 @@ import java.util.List;
|
||||||
public class SpringContextHolder implements ApplicationContextAware, DisposableBean {
|
public class SpringContextHolder implements ApplicationContextAware, DisposableBean {
|
||||||
|
|
||||||
private static ApplicationContext applicationContext = null;
|
private static ApplicationContext applicationContext = null;
|
||||||
private static List<CallBack> callBacks = new ArrayList<>();
|
private static final List<CallBack> CALL_BACKS = new ArrayList<>();
|
||||||
private static boolean addCallback = true;
|
private static boolean addCallback = true;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -44,7 +43,7 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB
|
||||||
*/
|
*/
|
||||||
public synchronized static void addCallBacks(CallBack callBack) {
|
public synchronized static void addCallBacks(CallBack callBack) {
|
||||||
if (addCallback) {
|
if (addCallback) {
|
||||||
SpringContextHolder.callBacks.add(callBack);
|
SpringContextHolder.CALL_BACKS.add(callBack);
|
||||||
} else {
|
} else {
|
||||||
log.warn("CallBack:{} 已无法添加!立即执行", callBack.getCallBackName());
|
log.warn("CallBack:{} 已无法添加!立即执行", callBack.getCallBackName());
|
||||||
callBack.executor();
|
callBack.executor();
|
||||||
|
@ -74,14 +73,13 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB
|
||||||
* @param property 属性key
|
* @param property 属性key
|
||||||
* @param defaultValue 默认值
|
* @param defaultValue 默认值
|
||||||
* @param requiredType 返回类型
|
* @param requiredType 返回类型
|
||||||
* @return
|
* @return /
|
||||||
*/
|
*/
|
||||||
public static <T> T getProperties(String property, T defaultValue, Class<T> requiredType) {
|
public static <T> T getProperties(String property, T defaultValue, Class<T> requiredType) {
|
||||||
T result = defaultValue;
|
T result = defaultValue;
|
||||||
try {
|
try {
|
||||||
result = getBean(Environment.class).getProperty(property, requiredType);
|
result = getBean(Environment.class).getProperty(property, requiredType);
|
||||||
} catch (Exception e) {
|
} catch (Exception ignored) {}
|
||||||
}
|
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -89,7 +87,7 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB
|
||||||
* 获取SpringBoot 配置信息
|
* 获取SpringBoot 配置信息
|
||||||
*
|
*
|
||||||
* @param property 属性key
|
* @param property 属性key
|
||||||
* @return
|
* @return /
|
||||||
*/
|
*/
|
||||||
public static String getProperties(String property) {
|
public static String getProperties(String property) {
|
||||||
return getProperties(property, null, String.class);
|
return getProperties(property, null, String.class);
|
||||||
|
@ -100,7 +98,7 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB
|
||||||
*
|
*
|
||||||
* @param property 属性key
|
* @param property 属性key
|
||||||
* @param requiredType 返回类型
|
* @param requiredType 返回类型
|
||||||
* @return
|
* @return /
|
||||||
*/
|
*/
|
||||||
public static <T> T getProperties(String property, Class<T> requiredType) {
|
public static <T> T getProperties(String property, Class<T> requiredType) {
|
||||||
return getProperties(property, null, requiredType);
|
return getProperties(property, null, requiredType);
|
||||||
|
@ -137,10 +135,10 @@ public class SpringContextHolder implements ApplicationContextAware, DisposableB
|
||||||
}
|
}
|
||||||
SpringContextHolder.applicationContext = applicationContext;
|
SpringContextHolder.applicationContext = applicationContext;
|
||||||
if (addCallback) {
|
if (addCallback) {
|
||||||
for (CallBack callBack : SpringContextHolder.callBacks) {
|
for (CallBack callBack : SpringContextHolder.CALL_BACKS) {
|
||||||
callBack.executor();
|
callBack.executor();
|
||||||
}
|
}
|
||||||
callBacks.clear();
|
CALL_BACKS.clear();
|
||||||
}
|
}
|
||||||
SpringContextHolder.addCallback = false;
|
SpringContextHolder.addCallback = false;
|
||||||
}
|
}
|
||||||
|
|
|
@ -22,16 +22,12 @@ import eu.bitwalker.useragentutils.Browser;
|
||||||
import eu.bitwalker.useragentutils.UserAgent;
|
import eu.bitwalker.useragentutils.UserAgent;
|
||||||
import org.lionsoul.ip2region.DataBlock;
|
import org.lionsoul.ip2region.DataBlock;
|
||||||
import org.lionsoul.ip2region.DbConfig;
|
import org.lionsoul.ip2region.DbConfig;
|
||||||
import org.lionsoul.ip2region.DbMakerConfigException;
|
|
||||||
import org.lionsoul.ip2region.DbSearcher;
|
import org.lionsoul.ip2region.DbSearcher;
|
||||||
import org.slf4j.Logger;
|
import org.slf4j.Logger;
|
||||||
import org.slf4j.LoggerFactory;
|
import org.slf4j.LoggerFactory;
|
||||||
import org.springframework.core.io.ClassPathResource;
|
import org.springframework.core.io.ClassPathResource;
|
||||||
|
|
||||||
import javax.servlet.http.HttpServletRequest;
|
import javax.servlet.http.HttpServletRequest;
|
||||||
import java.io.File;
|
import java.io.File;
|
||||||
import java.io.FileNotFoundException;
|
|
||||||
|
|
||||||
import java.net.InetAddress;
|
import java.net.InetAddress;
|
||||||
import java.net.UnknownHostException;
|
import java.net.UnknownHostException;
|
||||||
import java.util.Calendar;
|
import java.util.Calendar;
|
||||||
|
@ -42,28 +38,27 @@ import java.util.Date;
|
||||||
* 字符串工具类, 继承org.apache.commons.lang3.StringUtils类
|
* 字符串工具类, 继承org.apache.commons.lang3.StringUtils类
|
||||||
*/
|
*/
|
||||||
public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
|
|
||||||
private static final Logger log = LoggerFactory.getLogger(StringUtils.class);
|
private static final Logger log = LoggerFactory.getLogger(StringUtils.class);
|
||||||
private static boolean ipLocal = false;
|
private static boolean ipLocal = false;
|
||||||
private static DbSearcher searcher = null;
|
private static DbSearcher searcher = null;
|
||||||
|
private static final char SEPARATOR = '_';
|
||||||
|
private static final String UNKNOWN = "unknown";
|
||||||
|
|
||||||
static {
|
static {
|
||||||
SpringContextHolder.addCallBacks(() -> {
|
SpringContextHolder.addCallBacks(() -> {
|
||||||
StringUtils.ipLocal = SpringContextHolder.getProperties("ip.local-parsing", false, Boolean.class);
|
StringUtils.ipLocal = SpringContextHolder.getProperties("ip.local-parsing", false, Boolean.class);
|
||||||
if (ipLocal) {
|
if (ipLocal) {
|
||||||
/**
|
/*
|
||||||
* 此文件为独享 ,不必关闭
|
* 此文件为独享 ,不必关闭
|
||||||
*/
|
*/
|
||||||
String path = "ip2region/ip2region.db";
|
String path = "ip2region/ip2region.db";
|
||||||
String name = "ip2region.db";
|
String name = "ip2region.db";
|
||||||
DbConfig config = null;
|
DbConfig config;
|
||||||
try {
|
try {
|
||||||
config = new DbConfig();
|
config = new DbConfig();
|
||||||
File file = FileUtil.inputStreamToFile(new ClassPathResource(path).getInputStream(), name);
|
File file = FileUtil.inputStreamToFile(new ClassPathResource(path).getInputStream(), name);
|
||||||
searcher = new DbSearcher(config, file.getPath());
|
searcher = new DbSearcher(config, file.getPath());
|
||||||
} catch (DbMakerConfigException | FileNotFoundException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
} catch (NoSuchMethodException e) {
|
|
||||||
log.error(e.getMessage(), e);
|
|
||||||
} catch (Exception e) {
|
} catch (Exception e) {
|
||||||
log.error(e.getMessage(), e);
|
log.error(e.getMessage(), e);
|
||||||
}
|
}
|
||||||
|
@ -71,10 +66,6 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
private static final char SEPARATOR = '_';
|
|
||||||
|
|
||||||
private static final String UNKNOWN = "unknown";
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* 驼峰命名法工具
|
* 驼峰命名法工具
|
||||||
*
|
*
|
||||||
|
|
|
@ -68,6 +68,10 @@ jwt:
|
||||||
# 续期时间范围,默认 1小时,这里单位毫秒
|
# 续期时间范围,默认 1小时,这里单位毫秒
|
||||||
renew: 3600000
|
renew: 3600000
|
||||||
|
|
||||||
|
# IP 本地解析
|
||||||
|
ip:
|
||||||
|
local-parsing: true
|
||||||
|
|
||||||
#是否允许生成代码,生产环境设置为false
|
#是否允许生成代码,生产环境设置为false
|
||||||
generator:
|
generator:
|
||||||
enabled: false
|
enabled: false
|
||||||
|
|
Loading…
Reference in New Issue