升级到 Spring Boot 2.0.5 以及相关依赖库全面升级,采用J2Cache作为缓存。

This commit is contained in:
thinkgem
2018-09-22 21:12:45 +08:00
parent c9ecd3cfc8
commit d9e18a70c7
71 changed files with 3664 additions and 1138 deletions

View File

@@ -15,7 +15,7 @@ import java.util.regex.Pattern;
import org.apache.commons.codec.DecoderException;
import org.apache.commons.codec.binary.Base64;
import org.apache.commons.codec.binary.Hex;
import org.apache.commons.lang3.StringEscapeUtils;
import org.apache.commons.text.StringEscapeUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

View File

@@ -76,13 +76,12 @@ public class Md5Utils {
/**
* 获取文件的MD5值支持获取文件部分的MD5值
* uploader.md5File(file, 0, 10 * 1024 * 1024)
*/
public static String md5File(File file, int size) {
if (file != null && file.exists()){
InputStream in = null;
try {
try (InputStream in = FileUtils.openInputStream(file)){
byte[] bytes = null;
in = FileUtils.openInputStream(file);
if (size != -1 && file.length() >= size){
bytes = IOUtils.toByteArray(in, size);
}else{
@@ -91,8 +90,6 @@ public class Md5Utils {
return EncodeUtils.encodeHex(md5(bytes));
} catch (IOException e) {
return StringUtils.EMPTY;
} finally {
IOUtils.closeQuietly(in);
}
}
return StringUtils.EMPTY;

View File

@@ -242,14 +242,10 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
* @author ThinkGem 2016-7-4
*/
public static String readFileToString(String classResourcePath){
InputStream in = null;
try {
in = new ClassPathResource(classResourcePath).getInputStream();
try (InputStream in = new ClassPathResource(classResourcePath).getInputStream()){
return IOUtils.toString(in, Charsets.toCharset("UTF-8"));
} catch (IOException e) {
logger.warn("Error file convert: {}", e.getMessage());
}finally{
IOUtils.closeQuietly(in);
}
return null;
}
@@ -944,9 +940,9 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
projectPath = file.toString();
}
} catch (FileNotFoundException e) {
;
// 忽略异常
} catch (IOException e) {
e.printStackTrace();
// 忽略异常
}
// 取不到,取当前工作路径
if (StringUtils.isBlank(projectPath)){
@@ -982,9 +978,9 @@ public class FileUtils extends org.apache.commons.io.FileUtils {
webappPath = file.toString();
}
} catch (FileNotFoundException e) {
;
// 忽略异常
} catch (IOException e) {
e.printStackTrace();
// 忽略异常
}
// 取不到,取当前工作路径
if (StringUtils.isBlank(webappPath)){

View File

@@ -3,10 +3,13 @@
*/
package com.jeesite.common.io;
import java.io.Closeable;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
/**
* 数据流工具类
@@ -80,4 +83,24 @@ public class IOUtils extends org.apache.commons.io.IOUtils {
return fileOutputStream;
}
/**
* Closes a <code>Closeable</code> unconditionally.
*/
public static void closeQuietly(final InputStream input) {
closeQuietly((Closeable) input);
}
/**
* Closes a <code>Closeable</code> unconditionally.
*/
public static void closeQuietly(final Closeable closeable) {
try {
if (closeable != null) {
closeable.close();
}
} catch (final IOException ioe) {
// ignore
}
}
}

View File

@@ -12,7 +12,6 @@ import java.util.Set;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.io.IOUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.config.YamlPropertiesFactoryBean;
@@ -37,7 +36,7 @@ public class PropertiesUtils {
"classpath:config/application.yml", "classpath:application.yml"};
private static Logger logger = PropertiesUtils.initLogger();
private final Set<String> configSet = SetUtils.newLinkedHashSet();
private final Properties properties = new Properties();
/**
@@ -55,7 +54,7 @@ public class PropertiesUtils {
for(Resource resource : resources){
configSet.add("classpath:config/"+resource.getFilename());
}
configSet.add("classpath:config/jeesite.yml");
//configSet.add("classpath:config/jeesite.yml");
// 获取全局设置默认的配置文件(以下是支持环境配置的属性文件)
Set<String> set = SetUtils.newLinkedHashSet();
for (String configFile : DEFAULT_CONFIG_FILE){
@@ -83,7 +82,7 @@ public class PropertiesUtils {
}
for (String location : configFiles){
configSet.add(location);
if (StringUtils.isNotBlank(profiles) && !StringUtils.equals(profiles, "default")){
if (StringUtils.isNotBlank(profiles)){
if (location.endsWith(".properties")){
configSet.add(StringUtils.substringBeforeLast(location, ".properties")
+ "-" + profiles + ".properties");
@@ -108,14 +107,11 @@ public class PropertiesUtils {
Resource resource = ResourceUtils.getResource(location);
if (resource.exists()){
if (location.endsWith(".properties")){
InputStreamReader is = null;
try {
is = new InputStreamReader(resource.getInputStream(), "UTF-8");
try (InputStreamReader is = new InputStreamReader(resource.getInputStream(), "UTF-8")){
properties.load(is);
configSet.add(location);
} catch (IOException ex) {
logger.error("Load " + location + " failure. ", ex);
} finally {
IOUtils.closeQuietly(is);
}
}
else if (location.endsWith(".yml")){
@@ -125,18 +121,24 @@ public class PropertiesUtils {
properties.put(ObjectUtils.toString(entry.getKey()),
ObjectUtils.toString(entry.getValue()));
}
configSet.add(location);
}
}
} catch (Exception e) {
logger.error("Load " + location + " failure. ", e);
}
// 存储当前加载的配置文件路径和名称
properties.setProperty("configFiles", StringUtils.join(configFiles, ","));
}
}
/**
* 获取当前加载的属性
* 获取当前加载的属性文件
*/
public Set<String> getConfigSet() {
return configSet;
}
/**
* 获取当前加载的属性数据
*/
public Properties getProperties() {
return properties;

View File

@@ -67,14 +67,10 @@ public class ResourceUtils extends org.springframework.util.ResourceUtils {
* @author ThinkGem
*/
public static String getResourceFileContent(String location){
InputStream is = null;
try{
is = ResourceUtils.getResourceFileStream(location);
try(InputStream is = ResourceUtils.getResourceFileStream(location)){
return IOUtils.toString(is, "UTF-8");
}catch (IOException e) {
throw ExceptionUtils.unchecked(e);
}finally{
IOUtils.closeQuietly(is);
}
}

View File

@@ -16,8 +16,6 @@ import org.nustaq.serialization.FSTConfiguration;
import org.springframework.beans.BeanUtils;
import org.springframework.core.NamedThreadLocal;
import com.jeesite.common.io.IOUtils;
/**
* 对象操作工具类, 继承org.apache.commons.lang3.ObjectUtils类
* @author ThinkGem
@@ -118,9 +116,13 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
if (source == null){
return null;
}
Object target = BeanUtils.instantiate(source.getClass());
BeanUtils.copyProperties(source, target, ignoreProperties);
return target;
try {
Object target = source.getClass().newInstance();
BeanUtils.copyProperties(source, target, ignoreProperties);
return target;
} catch (InstantiationException | IllegalAccessException e) {
throw ExceptionUtils.unchecked(e);
}
}
/**
@@ -162,18 +164,12 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
}
long beginTime = System.currentTimeMillis();
byte[] bytes = null;
ObjectOutputStream oos = null;
ByteArrayOutputStream baos = null;
try {
baos = new ByteArrayOutputStream();
oos = new ObjectOutputStream(baos);
try (ByteArrayOutputStream baos = new ByteArrayOutputStream();
ObjectOutputStream oos = new ObjectOutputStream(baos);) {
oos.writeObject(object);
bytes = baos.toByteArray();
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(oos);
IOUtils.closeQuietly(baos);
}
long totalTime = System.currentTimeMillis() - beginTime;
if (totalTime > 3000){
@@ -193,19 +189,13 @@ public class ObjectUtils extends org.apache.commons.lang3.ObjectUtils {
}
long beginTime = System.currentTimeMillis();
Object object = null;
ByteArrayInputStream bais = null;
ObjectInputStream ois = null;
try {
if (bytes.length > 0) {
bais = new ByteArrayInputStream(bytes);
ois = new ObjectInputStream(bais);
if (bytes.length > 0) {
try (ByteArrayInputStream bais = new ByteArrayInputStream(bytes);
ObjectInputStream ois = new ObjectInputStream(bais);) {
object = ois.readObject();
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
} finally {
IOUtils.closeQuietly(ois);
IOUtils.closeQuietly(bais);
}
long totalTime = System.currentTimeMillis() - beginTime;
if (totalTime > 3000){

View File

@@ -9,8 +9,6 @@ import java.util.Random;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
import org.apache.commons.lang3.StringEscapeUtils;
import com.jeesite.common.codec.EncodeUtils;
import com.jeesite.common.collect.ListUtils;
@@ -140,7 +138,7 @@ public class StringUtils extends org.apache.commons.lang3.StringUtils {
try {
StringBuilder sb = new StringBuilder();
int currentLength = 0;
for (char c : stripHtml(StringEscapeUtils.unescapeHtml4(str)).toCharArray()) {
for (char c : stripHtml(EncodeUtils.decodeHtml(str)).toCharArray()) {
currentLength += String.valueOf(c).getBytes("GBK").length;
if (currentLength <= length - 3) {
sb.append(c);

View File

@@ -1,37 +0,0 @@
/**
* Copyright (c) 2013-Now http://jeesite.com All rights reserved.
*/
package com.jeesite.common.mail;
/**
* 发送电子邮件
*/
@Deprecated
public class EmailUtils {
/**
* 发送邮件
* @param toAddress 接收地址
* @param subject 标题
* @param content 内容
* @return
*/
@Deprecated
public static boolean sendEmail(String toAddress, String subject, String content) {
return com.jeesite.common.msg.EmailUtils.send(toAddress, subject, content);
}
/**
* 发送邮件
* @param toAddress 接收地址
* @param subject 标题
* @param content 内容
* @return
*/
@Deprecated
public static boolean sendEmail(String fromAddress, String fromPassword, String fromHostName,
String sslOnConnect, String sslSmtpPort, String toAddress, String subject, String content) {
return com.jeesite.common.msg.EmailUtils.send(fromAddress, fromPassword, fromHostName, sslOnConnect, sslSmtpPort, toAddress, subject, content);
}
}

View File

@@ -1,59 +0,0 @@
/**
* Copyright (c) 2005-2012 springside.org.cn
*
* Licensed under the Apache License, Version 2.0 (the "License");
*/
package com.jeesite.common.mapper;
import java.util.Collection;
import java.util.List;
import org.dozer.DozerBeanMapper;
import com.jeesite.common.collect.ListUtils;
/**
* 简单封装Dozer, 实现深度转换Bean<->Bean的Mapper.实现:
*
* 1. 持有Mapper的单例.
* 2. 返回值类型转换.
* 3. 批量转换Collection中的所有对象.
* 4. 区分创建新的B对象与将对象A值复制到已存在的B对象两种函数.
*
* @author calvin
* @version 2013-01-15
*/
public class BeanMapper {
/**
* 持有Dozer单例, 避免重复创建DozerMapper消耗资源.
*/
private static DozerBeanMapper dozer = new DozerBeanMapper();
/**
* 基于Dozer转换对象的类型.
*/
public static <T> T map(Object source, Class<T> destinationClass) {
return dozer.map(source, destinationClass);
}
/**
* 基于Dozer转换Collection中对象的类型.
*/
@SuppressWarnings("rawtypes")
public static <T> List<T> mapList(Collection sourceList, Class<T> destinationClass) {
List<T> destinationList = ListUtils.newArrayList();
for (Object sourceObject : sourceList) {
T destinationObject = dozer.map(sourceObject, destinationClass);
destinationList.add(destinationObject);
}
return destinationList;
}
/**
* 基于Dozer将对象A的值拷贝到对象B中.
*/
public static void copy(Object source, Object destinationObject) {
dozer.map(source, destinationObject);
}
}

View File

@@ -43,20 +43,21 @@ public class ReflectUtils {
* 调用Getter方法.
* 支持多级,如:对象名.对象名.方法
*/
public static Object invokeGetter(Object obj, String propertyName) {
@SuppressWarnings("unchecked")
public static <E> E invokeGetter(Object obj, String propertyName) {
Object object = obj;
for (String name : StringUtils.split(propertyName, ".")){
String getterMethodName = GETTER_PREFIX + StringUtils.capitalize(name);
object = invokeMethod(object, getterMethodName, new Class[] {}, new Object[] {});
}
return object;
return (E)object;
}
/**
* 调用Setter方法, 仅匹配方法名。
* 支持多级,如:对象名.对象名.方法
*/
public static void invokeSetter(Object obj, String propertyName, Object value) {
public static <E> void invokeSetter(Object obj, String propertyName, E value) {
Object object = obj;
String[] names = StringUtils.split(propertyName, ".");
for (int i=0; i<names.length; i++){
@@ -73,16 +74,17 @@ public class ReflectUtils {
/**
* 直接读取对象属性值, 无视private/protected修饰符, 不经过getter函数.
*/
public static Object getFieldValue(final Object obj, final String fieldName) {
@SuppressWarnings("unchecked")
public static <E> E getFieldValue(final Object obj, final String fieldName) {
Field field = getAccessibleField(obj, fieldName);
if (field == null) {
//throw new IllegalArgumentException("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
logger.warn("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
return null;
}
Object result = null;
E result = null;
try {
result = field.get(obj);
result = (E)field.get(obj);
} catch (IllegalAccessException e) {
logger.error("不可能抛出的异常{}", e.getMessage());
}
@@ -92,7 +94,7 @@ public class ReflectUtils {
/**
* 直接设置对象属性值, 无视private/protected修饰符, 不经过setter函数.
*/
public static void setFieldValue(final Object obj, final String fieldName, final Object value) {
public static <E> void setFieldValue(final Object obj, final String fieldName, final E value) {
Field field = getAccessibleField(obj, fieldName);
if (field == null) {
//throw new IllegalArgumentException("在 [" + obj.getClass() + "] 中,没有找到 [" + fieldName + "] 字段 ");
@@ -111,7 +113,8 @@ public class ReflectUtils {
* 用于一次性调用的情况否则应使用getAccessibleMethod()函数获得Method后反复调用.
* 同时匹配方法名+参数类型,
*/
public static Object invokeMethod(final Object obj, final String methodName, final Class<?>[] parameterTypes,
@SuppressWarnings("unchecked")
public static <E> E invokeMethod(final Object obj, final String methodName, final Class<?>[] parameterTypes,
final Object[] args) {
if (obj == null || methodName == null){
return null;
@@ -123,7 +126,7 @@ public class ReflectUtils {
return null;
}
try {
return method.invoke(obj, args);
return (E)method.invoke(obj, args);
} catch (Exception e) {
String msg = "method: "+method+", obj: "+obj+", args: "+args+"";
throw convertReflectionExceptionToUnchecked(msg, e);
@@ -135,7 +138,8 @@ public class ReflectUtils {
* 用于一次性调用的情况否则应使用getAccessibleMethodByName()函数获得Method后反复调用.
* 只匹配函数名,如果有多个同名函数调用第一个。
*/
public static Object invokeMethodByName(final Object obj, final String methodName, final Object[] args) {
@SuppressWarnings("unchecked")
public static <E> E invokeMethodByName(final Object obj, final String methodName, final Object[] args) {
Method method = getAccessibleMethodByName(obj, methodName, args.length);
if (method == null) {
// 如果为空不报错,直接返回空。
@@ -171,7 +175,7 @@ public class ReflectUtils {
}
}
}
return method.invoke(obj, args);
return (E)method.invoke(obj, args);
} catch (Exception e) {
String msg = "method: "+method+", obj: "+obj+", args: "+args+"";
throw convertReflectionExceptionToUnchecked(msg, e);