From 4e4ca2082867a4c4cd425e6e5c9e98a59832d0d0 Mon Sep 17 00:00:00 2001 From: Jie Zheng <201507802@qq.com> Date: Wed, 22 Jan 2025 10:17:28 +0800 Subject: [PATCH] =?UTF-8?q?feat:=20=E5=8D=87=E7=BA=A7=E9=83=A8=E5=88=86?= =?UTF-8?q?=E4=BE=9D=E8=B5=96=E4=BA=8E=E4=BC=98=E5=8C=96=E4=BB=A3=E7=A0=81?= =?UTF-8?q?=EF=BC=88=E5=8D=87=E7=BA=A7fastjson2=EF=BC=8C=E4=B8=8D=E5=86=8D?= =?UTF-8?q?=E5=85=BC=E5=AE=B9fastjson1=EF=BC=89=EF=BC=8C=E5=85=B6=E4=BB=96?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=E7=9C=8B=E8=AF=A6=E6=83=85=20=E5=8D=87?= =?UTF-8?q?=E7=BA=A7=20hutool=EF=BC=9A5.8.35=20=E5=8D=87=E7=BA=A7=20oshi-c?= =?UTF-8?q?ore=EF=BC=9A6.6.5=20=E5=8D=87=E7=BA=A7=20mica-ip2region?= =?UTF-8?q?=EF=BC=9A2.7.18.9=20=E5=8D=87=E7=BA=A7=20poi=EF=BC=9A5.4.0=20?= =?UTF-8?q?=E5=8D=87=E7=BA=A7=20commons-text=EF=BC=9A1.13.0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- eladmin-common/pom.xml | 6 +- .../zhengjie/config/RedisConfiguration.java | 38 ++++------ .../zhengjie/config/RemoveDruidAdConfig.java | 2 +- .../config/webConfig/ConfigurerAdapter.java | 11 +-- .../config/webConfig/SwaggerConfig.java | 2 +- .../java/me/zhengjie/utils/SecurityUtils.java | 6 +- .../me/zhengjie/utils/SpringBeanHolder.java | 2 +- eladmin-generator/pom.xml | 4 +- .../src/main/resources/template/admin/Dto.ftl | 4 +- eladmin-logging/pom.xml | 4 +- .../service/impl/SysLogServiceImpl.java | 4 +- eladmin-system/pom.xml | 26 +++---- .../maint/websocket/WebSocketServer.java | 2 +- .../modules/quartz/utils/QuartzRunnable.java | 2 +- .../security/service/dto/JwtUserDto.java | 2 +- .../zhengjie/modules/system/domain/Dept.java | 2 +- .../zhengjie/modules/system/domain/Menu.java | 3 +- .../zhengjie/modules/system/domain/Role.java | 2 +- .../modules/system/service/dto/UserDto.java | 2 +- eladmin-tools/pom.xml | 4 +- .../service/impl/QiNiuServiceImpl.java | 2 +- pom.xml | 74 ++++++++++++------- 22 files changed, 104 insertions(+), 100 deletions(-) diff --git a/eladmin-common/pom.xml b/eladmin-common/pom.xml index dd010d62..e1510a7a 100644 --- a/eladmin-common/pom.xml +++ b/eladmin-common/pom.xml @@ -1,7 +1,5 @@ - + eladmin me.zhengjie @@ -9,7 +7,7 @@ 4.0.0 - 5.8.21 + 5.8.35 eladmin-common diff --git a/eladmin-common/src/main/java/me/zhengjie/config/RedisConfiguration.java b/eladmin-common/src/main/java/me/zhengjie/config/RedisConfiguration.java index 1f757fe4..cdd47e4b 100644 --- a/eladmin-common/src/main/java/me/zhengjie/config/RedisConfiguration.java +++ b/eladmin-common/src/main/java/me/zhengjie/config/RedisConfiguration.java @@ -15,9 +15,9 @@ */ package me.zhengjie.config; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.parser.ParserConfig; -import com.alibaba.fastjson.serializer.SerializerFeature; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONFactory; +import com.alibaba.fastjson2.JSONWriter; import lombok.extern.slf4j.Slf4j; import org.apache.commons.codec.digest.DigestUtils; import org.springframework.cache.Cache; @@ -33,8 +33,8 @@ import org.springframework.data.redis.connection.RedisConnectionFactory; import org.springframework.data.redis.core.RedisTemplate; import org.springframework.data.redis.serializer.RedisSerializationContext; import org.springframework.data.redis.serializer.RedisSerializer; +import org.springframework.data.redis.serializer.SerializationException; import org.springframework.data.redis.serializer.StringRedisSerializer; - import java.nio.charset.StandardCharsets; import java.time.Duration; import java.util.HashMap; @@ -65,25 +65,13 @@ public class RedisConfiguration { @Bean(name = "redisTemplate") public RedisTemplate redisTemplate(RedisConnectionFactory redisConnectionFactory) { RedisTemplate template = new RedisTemplate<>(); - //序列化 + // 指定 key 和 value 的序列化方案 FastJsonRedisSerializer fastJsonRedisSerializer = new FastJsonRedisSerializer<>(Object.class); // value值的序列化采用fastJsonRedisSerializer template.setValueSerializer(fastJsonRedisSerializer); template.setHashValueSerializer(fastJsonRedisSerializer); - // fastjson 升级到 1.2.83 后需要指定序列化白名单 - ParserConfig.getGlobalInstance().addAccept("me.zhengjie.domain"); - ParserConfig.getGlobalInstance().addAccept("me.zhengjie.service.dto"); - // 模块内的实体类 - ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.mnt.domain"); - ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.quartz.domain"); - ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.system.domain"); - // 模块内的 Dto - ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.mnt.service.dto"); - ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.quartz.service.dto"); - ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.security.service.dto"); - ParserConfig.getGlobalInstance().addAccept("me.zhengjie.modules.system.service.dto"); - // 分页返回数据 - ParserConfig.getGlobalInstance().addAccept("me.zhengjie.utils.PageResult"); + // 设置fastJson的序列化白名单 + JSONFactory.getDefaultObjectReaderProvider().addAutoTypeAccept("me.zhengjie"); // key的序列化采用StringRedisSerializer template.setKeySerializer(new StringRedisSerializer()); template.setHashKeySerializer(new StringRedisSerializer()); @@ -92,7 +80,7 @@ public class RedisConfiguration { } /** - * 缓存管理器,需要指定使用 + * 缓存管理器 * @param redisConnectionFactory / * @return 缓存管理器 */ @@ -132,7 +120,7 @@ public class RedisConfiguration { } @Bean - @SuppressWarnings("all") + @SuppressWarnings({"unchecked","all"}) public CacheErrorHandler errorHandler() { return new SimpleCacheErrorHandler() { @Override @@ -174,15 +162,17 @@ public class RedisConfiguration { } @Override - public byte[] serialize(T t) { + public byte[] serialize(T t) throws SerializationException + { if (t == null) { return new byte[0]; } - return JSON.toJSONString(t, SerializerFeature.WriteClassName).getBytes(StandardCharsets.UTF_8); + return JSON.toJSONString(t, JSONWriter.Feature.WriteClassName).getBytes(StandardCharsets.UTF_8); } @Override - public T deserialize(byte[] bytes) { + public T deserialize(byte[] bytes) throws SerializationException + { if (bytes == null || bytes.length == 0) { return null; } diff --git a/eladmin-common/src/main/java/me/zhengjie/config/RemoveDruidAdConfig.java b/eladmin-common/src/main/java/me/zhengjie/config/RemoveDruidAdConfig.java index f432de47..8757ead1 100644 --- a/eladmin-common/src/main/java/me/zhengjie/config/RemoveDruidAdConfig.java +++ b/eladmin-common/src/main/java/me/zhengjie/config/RemoveDruidAdConfig.java @@ -21,7 +21,7 @@ import java.io.IOException; * @date 2025-01-11 **/ @Configuration -@SuppressWarnings("all") +@SuppressWarnings({"unchecked","all"}) @ConditionalOnWebApplication @AutoConfigureAfter(DruidDataSourceAutoConfigure.class) @ConditionalOnProperty(name = "spring.datasource.druid.stat-view-servlet.enabled", diff --git a/eladmin-common/src/main/java/me/zhengjie/config/webConfig/ConfigurerAdapter.java b/eladmin-common/src/main/java/me/zhengjie/config/webConfig/ConfigurerAdapter.java index 547ae7fa..72c54bbe 100644 --- a/eladmin-common/src/main/java/me/zhengjie/config/webConfig/ConfigurerAdapter.java +++ b/eladmin-common/src/main/java/me/zhengjie/config/webConfig/ConfigurerAdapter.java @@ -15,9 +15,9 @@ */ package me.zhengjie.config.webConfig; -import com.alibaba.fastjson.serializer.SerializerFeature; -import com.alibaba.fastjson.support.config.FastJsonConfig; -import com.alibaba.fastjson.support.spring.FastJsonHttpMessageConverter; +import com.alibaba.fastjson2.JSONWriter; +import com.alibaba.fastjson2.support.config.FastJsonConfig; +import com.alibaba.fastjson2.support.spring.http.converter.FastJsonHttpMessageConverter; import me.zhengjie.config.properties.FileProperties; import org.springframework.context.annotation.Bean; import org.springframework.context.annotation.Configuration; @@ -74,13 +74,14 @@ public class ConfigurerAdapter implements WebMvcConfigurer { @Override public void configureMessageConverters(List> converters) { - // 使用 fastjson 序列化,会导致 @JsonIgnore 失效,可以使用 @JSONField(serialize = false) 替换 + // 配置 FastJsonHttpMessageConverter FastJsonHttpMessageConverter converter = new FastJsonHttpMessageConverter(); List supportMediaTypeList = new ArrayList<>(); supportMediaTypeList.add(MediaType.APPLICATION_JSON); FastJsonConfig config = new FastJsonConfig(); config.setDateFormat("yyyy-MM-dd HH:mm:ss"); - config.setSerializerFeatures(SerializerFeature.DisableCircularReferenceDetect); + // 开启引用检测 + config.setWriterFeatures(JSONWriter.Feature.ReferenceDetection); converter.setFastJsonConfig(config); converter.setSupportedMediaTypes(supportMediaTypeList); converter.setDefaultCharset(StandardCharsets.UTF_8); diff --git a/eladmin-common/src/main/java/me/zhengjie/config/webConfig/SwaggerConfig.java b/eladmin-common/src/main/java/me/zhengjie/config/webConfig/SwaggerConfig.java index cef73344..2b73c897 100644 --- a/eladmin-common/src/main/java/me/zhengjie/config/webConfig/SwaggerConfig.java +++ b/eladmin-common/src/main/java/me/zhengjie/config/webConfig/SwaggerConfig.java @@ -67,7 +67,7 @@ public class SwaggerConfig { private final ApplicationContext applicationContext; @Bean - @SuppressWarnings("all") + @SuppressWarnings({"unchecked","all"}) public Docket createRestApi() { return new Docket(DocumentationType.SWAGGER_2) .enable(enabled) diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/SecurityUtils.java b/eladmin-common/src/main/java/me/zhengjie/utils/SecurityUtils.java index fb98424a..1c1f8134 100644 --- a/eladmin-common/src/main/java/me/zhengjie/utils/SecurityUtils.java +++ b/eladmin-common/src/main/java/me/zhengjie/utils/SecurityUtils.java @@ -18,9 +18,9 @@ package me.zhengjie.utils; import cn.hutool.core.collection.CollUtil; import cn.hutool.jwt.JWT; import cn.hutool.jwt.JWTUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONArray; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONArray; +import com.alibaba.fastjson2.JSONObject; import lombok.extern.slf4j.Slf4j; import me.zhengjie.utils.enums.DataScopeEnum; import org.springframework.beans.factory.annotation.Value; diff --git a/eladmin-common/src/main/java/me/zhengjie/utils/SpringBeanHolder.java b/eladmin-common/src/main/java/me/zhengjie/utils/SpringBeanHolder.java index ca9cdfc0..ef7ac7b3 100644 --- a/eladmin-common/src/main/java/me/zhengjie/utils/SpringBeanHolder.java +++ b/eladmin-common/src/main/java/me/zhengjie/utils/SpringBeanHolder.java @@ -31,7 +31,7 @@ import java.util.List; * @date 2019-01-07 */ @Slf4j -@SuppressWarnings("all") +@SuppressWarnings({"unchecked","all"}) public class SpringBeanHolder implements ApplicationContextAware, DisposableBean { private static ApplicationContext applicationContext = null; diff --git a/eladmin-generator/pom.xml b/eladmin-generator/pom.xml index 3584959b..46b8e757 100644 --- a/eladmin-generator/pom.xml +++ b/eladmin-generator/pom.xml @@ -1,7 +1,5 @@ - + eladmin me.zhengjie diff --git a/eladmin-generator/src/main/resources/template/admin/Dto.ftl b/eladmin-generator/src/main/resources/template/admin/Dto.ftl index 3dab87ac..cc0f8f06 100644 --- a/eladmin-generator/src/main/resources/template/admin/Dto.ftl +++ b/eladmin-generator/src/main/resources/template/admin/Dto.ftl @@ -24,8 +24,8 @@ import java.math.BigDecimal; import java.io.Serializable; <#if !auto && pkColumnType = 'Long'> -import com.alibaba.fastjson.annotation.JSONField; -import com.alibaba.fastjson.serializer.ToStringSerializer; +import com.alibaba.fastjson2.annotation.JSONField; +import com.alibaba.fastjson2.serializer.ToStringSerializer; import io.swagger.annotations.ApiModelProperty; diff --git a/eladmin-logging/pom.xml b/eladmin-logging/pom.xml index 8613702d..db4808cb 100644 --- a/eladmin-logging/pom.xml +++ b/eladmin-logging/pom.xml @@ -1,7 +1,5 @@ - + eladmin me.zhengjie diff --git a/eladmin-logging/src/main/java/me/zhengjie/service/impl/SysLogServiceImpl.java b/eladmin-logging/src/main/java/me/zhengjie/service/impl/SysLogServiceImpl.java index 74598b8d..bcff3710 100644 --- a/eladmin-logging/src/main/java/me/zhengjie/service/impl/SysLogServiceImpl.java +++ b/eladmin-logging/src/main/java/me/zhengjie/service/impl/SysLogServiceImpl.java @@ -17,8 +17,8 @@ package me.zhengjie.service.impl; import cn.hutool.core.lang.Dict; import cn.hutool.core.util.ObjectUtil; -import com.alibaba.fastjson.JSON; -import com.alibaba.fastjson.JSONObject; +import com.alibaba.fastjson2.JSON; +import com.alibaba.fastjson2.JSONObject; import lombok.RequiredArgsConstructor; import me.zhengjie.domain.SysLog; import me.zhengjie.repository.LogRepository; diff --git a/eladmin-system/pom.xml b/eladmin-system/pom.xml index a7b837cc..667dacb6 100644 --- a/eladmin-system/pom.xml +++ b/eladmin-system/pom.xml @@ -1,7 +1,5 @@ - + eladmin me.zhengjie @@ -63,22 +61,22 @@ - - ch.ethz.ganymed - ganymed-ssh2 - build210 - - - com.jcraft - jsch - 0.1.55 - + + ch.ethz.ganymed + ganymed-ssh2 + build210 + + + com.jcraft + jsch + 0.1.55 + com.github.oshi oshi-core - 6.1.4 + 6.6.5 diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/maint/websocket/WebSocketServer.java b/eladmin-system/src/main/java/me/zhengjie/modules/maint/websocket/WebSocketServer.java index 2441707f..c48a7b95 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/maint/websocket/WebSocketServer.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/maint/websocket/WebSocketServer.java @@ -15,7 +15,7 @@ */ package me.zhengjie.modules.maint.websocket; -import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson2.JSON; import lombok.extern.slf4j.Slf4j; import org.springframework.stereotype.Component; import javax.websocket.*; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzRunnable.java b/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzRunnable.java index a8f708dc..0b4751a4 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzRunnable.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/quartz/utils/QuartzRunnable.java @@ -45,7 +45,7 @@ public class QuartzRunnable implements Callable { } @Override - @SuppressWarnings("all") + @SuppressWarnings({"unchecked","all"}) public Object call() throws Exception { ReflectionUtils.makeAccessible(method); if (StringUtils.isNotBlank(params)) { diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/JwtUserDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/JwtUserDto.java index ebb1a1de..819a9bd4 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/JwtUserDto.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/security/service/dto/JwtUserDto.java @@ -15,7 +15,7 @@ */ package me.zhengjie.modules.security.service.dto; -import com.alibaba.fastjson.annotation.JSONField; +import com.alibaba.fastjson2.annotation.JSONField; import io.swagger.annotations.ApiModelProperty; import lombok.AllArgsConstructor; import lombok.Getter; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/Dept.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/Dept.java index 3130f19f..4f9a669b 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/Dept.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/Dept.java @@ -15,7 +15,7 @@ */ package me.zhengjie.modules.system.domain; -import com.alibaba.fastjson.annotation.JSONField; +import com.alibaba.fastjson2.annotation.JSONField; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/Menu.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/Menu.java index 0e649670..34734e2e 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/Menu.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/Menu.java @@ -15,12 +15,11 @@ */ package me.zhengjie.modules.system.domain; -import com.alibaba.fastjson.annotation.JSONField; +import com.alibaba.fastjson2.annotation.JSONField; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; import me.zhengjie.base.BaseEntity; - import javax.persistence.*; import javax.validation.constraints.NotNull; import java.io.Serializable; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/Role.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/Role.java index 127a758d..1225e5ea 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/Role.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/domain/Role.java @@ -15,7 +15,7 @@ */ package me.zhengjie.modules.system.domain; -import com.alibaba.fastjson.annotation.JSONField; +import com.alibaba.fastjson2.annotation.JSONField; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; diff --git a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserDto.java b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserDto.java index 23f7398d..f8ee0b51 100644 --- a/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserDto.java +++ b/eladmin-system/src/main/java/me/zhengjie/modules/system/service/dto/UserDto.java @@ -15,7 +15,7 @@ */ package me.zhengjie.modules.system.service.dto; -import com.alibaba.fastjson.annotation.JSONField; +import com.alibaba.fastjson2.annotation.JSONField; import io.swagger.annotations.ApiModelProperty; import lombok.Getter; import lombok.Setter; diff --git a/eladmin-tools/pom.xml b/eladmin-tools/pom.xml index 7c85d8b0..24cd54cd 100644 --- a/eladmin-tools/pom.xml +++ b/eladmin-tools/pom.xml @@ -1,7 +1,5 @@ - + eladmin me.zhengjie diff --git a/eladmin-tools/src/main/java/me/zhengjie/service/impl/QiNiuServiceImpl.java b/eladmin-tools/src/main/java/me/zhengjie/service/impl/QiNiuServiceImpl.java index 01229feb..0fe81f3b 100644 --- a/eladmin-tools/src/main/java/me/zhengjie/service/impl/QiNiuServiceImpl.java +++ b/eladmin-tools/src/main/java/me/zhengjie/service/impl/QiNiuServiceImpl.java @@ -15,7 +15,7 @@ */ package me.zhengjie.service.impl; -import com.alibaba.fastjson.JSON; +import com.alibaba.fastjson2.JSON; import com.qiniu.common.QiniuException; import com.qiniu.http.Response; import com.qiniu.storage.BucketManager; diff --git a/pom.xml b/pom.xml index 45a718a8..e9304dd7 100644 --- a/pom.xml +++ b/pom.xml @@ -25,13 +25,11 @@ - 2.17.0 1.2.9 UTF-8 UTF-8 1.8 - 2.9.2 - 1.2.83 + 2.0.54 1.2.19 2.11.1 1.4.2.Final @@ -54,6 +52,13 @@ org.springframework.boot spring-boot-starter-web + + + + org.springframework.boot + spring-boot-starter-json + + @@ -108,11 +113,24 @@ - com.github.xiaoymin knife4j-spring-boot-starter 3.0.3 + + + + io.swagger + swagger-annotations + + + + + + + io.swagger + swagger-annotations + 1.5.22 @@ -131,11 +149,11 @@ ${druid.version} - + net.dreamlu mica-ip2region - 2.7.12 + 2.7.18.9 @@ -149,12 +167,12 @@ org.apache.poi poi - 5.2.0 + 5.4.0 org.apache.poi poi-ooxml - 5.2.0 + 5.4.0 xerces @@ -162,11 +180,30 @@ 2.12.2 - + - com.alibaba - fastjson - ${fastjson.version} + com.alibaba.fastjson2 + fastjson2 + ${fastjson2.version} + + + + com.alibaba.fastjson2 + fastjson2-extension-spring5 + ${fastjson2.version} + + + + + com.github.whvcse + easy-captcha + 1.6.2 + + + + org.apache.commons + commons-text + 1.13.0 @@ -186,19 +223,6 @@ javax.inject 1 - - - - com.github.whvcse - easy-captcha - 1.6.2 - - - - org.apache.commons - commons-text - 1.10.0 -