Commit ab800aa891829422f814683cb4fe77ba057a8d16
1 parent
50371b36
1. 简化 JsonUtils 初始化方式,去掉 BeanPostProcessor
2. 减少日志打印 目的:优化启动速度
Showing
5 changed files
with
27 additions
and
35 deletions
yudao-framework/yudao-common/src/main/java/cn/iocoder/yudao/framework/common/util/json/JsonUtils.java
| @@ -10,7 +10,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; | @@ -10,7 +10,6 @@ import com.fasterxml.jackson.databind.ObjectMapper; | ||
| 10 | import com.fasterxml.jackson.databind.SerializationFeature; | 10 | import com.fasterxml.jackson.databind.SerializationFeature; |
| 11 | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; | 11 | import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule; |
| 12 | import lombok.SneakyThrows; | 12 | import lombok.SneakyThrows; |
| 13 | -import lombok.experimental.UtilityClass; | ||
| 14 | import lombok.extern.slf4j.Slf4j; | 13 | import lombok.extern.slf4j.Slf4j; |
| 15 | 14 | ||
| 16 | import java.io.IOException; | 15 | import java.io.IOException; |
| @@ -23,7 +22,6 @@ import java.util.List; | @@ -23,7 +22,6 @@ import java.util.List; | ||
| 23 | * | 22 | * |
| 24 | * @author 芋道源码 | 23 | * @author 芋道源码 |
| 25 | */ | 24 | */ |
| 26 | -@UtilityClass | ||
| 27 | @Slf4j | 25 | @Slf4j |
| 28 | public class JsonUtils { | 26 | public class JsonUtils { |
| 29 | 27 |
yudao-framework/yudao-spring-boot-starter-biz-sms/src/main/java/cn/iocoder/yudao/framework/sms/core/client/impl/AbstractSmsClient.java
| @@ -40,7 +40,7 @@ public abstract class AbstractSmsClient implements SmsClient { | @@ -40,7 +40,7 @@ public abstract class AbstractSmsClient implements SmsClient { | ||
| 40 | */ | 40 | */ |
| 41 | public final void init() { | 41 | public final void init() { |
| 42 | doInit(); | 42 | doInit(); |
| 43 | - log.info("[init][配置({}) 初始化完成]", properties); | 43 | + log.debug("[init][配置({}) 初始化完成]", properties); |
| 44 | } | 44 | } |
| 45 | 45 | ||
| 46 | /** | 46 | /** |
yudao-framework/yudao-spring-boot-starter-file/src/main/java/cn/iocoder/yudao/framework/file/core/client/AbstractFileClient.java
| @@ -30,7 +30,7 @@ public abstract class AbstractFileClient<Config extends FileClientConfig> implem | @@ -30,7 +30,7 @@ public abstract class AbstractFileClient<Config extends FileClientConfig> implem | ||
| 30 | */ | 30 | */ |
| 31 | public final void init() { | 31 | public final void init() { |
| 32 | doInit(); | 32 | doInit(); |
| 33 | - log.info("[init][配置({}) 初始化完成]", config); | 33 | + log.debug("[init][配置({}) 初始化完成]", config); |
| 34 | } | 34 | } |
| 35 | 35 | ||
| 36 | /** | 36 | /** |
yudao-framework/yudao-spring-boot-starter-web/src/main/java/cn/iocoder/yudao/framework/jackson/config/YudaoJacksonAutoConfiguration.java
| 1 | package cn.iocoder.yudao.framework.jackson.config; | 1 | package cn.iocoder.yudao.framework.jackson.config; |
| 2 | 2 | ||
| 3 | -import cn.iocoder.yudao.framework.jackson.core.databind.NumberSerializer; | 3 | +import cn.hutool.core.collection.CollUtil; |
| 4 | +import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | ||
| 4 | import cn.iocoder.yudao.framework.jackson.core.databind.LocalDateTimeDeserializer; | 5 | import cn.iocoder.yudao.framework.jackson.core.databind.LocalDateTimeDeserializer; |
| 5 | import cn.iocoder.yudao.framework.jackson.core.databind.LocalDateTimeSerializer; | 6 | import cn.iocoder.yudao.framework.jackson.core.databind.LocalDateTimeSerializer; |
| 6 | -import cn.iocoder.yudao.framework.common.util.json.JsonUtils; | 7 | +import cn.iocoder.yudao.framework.jackson.core.databind.NumberSerializer; |
| 7 | import com.fasterxml.jackson.databind.ObjectMapper; | 8 | import com.fasterxml.jackson.databind.ObjectMapper; |
| 8 | import com.fasterxml.jackson.databind.module.SimpleModule; | 9 | import com.fasterxml.jackson.databind.module.SimpleModule; |
| 9 | import lombok.extern.slf4j.Slf4j; | 10 | import lombok.extern.slf4j.Slf4j; |
| 10 | -import org.springframework.beans.BeansException; | ||
| 11 | -import org.springframework.beans.factory.config.BeanPostProcessor; | ||
| 12 | import org.springframework.boot.autoconfigure.AutoConfiguration; | 11 | import org.springframework.boot.autoconfigure.AutoConfiguration; |
| 13 | import org.springframework.context.annotation.Bean; | 12 | import org.springframework.context.annotation.Bean; |
| 14 | 13 | ||
| 15 | import java.time.LocalDateTime; | 14 | import java.time.LocalDateTime; |
| 15 | +import java.util.List; | ||
| 16 | 16 | ||
| 17 | @AutoConfiguration | 17 | @AutoConfiguration |
| 18 | @Slf4j | 18 | @Slf4j |
| 19 | public class YudaoJacksonAutoConfiguration { | 19 | public class YudaoJacksonAutoConfiguration { |
| 20 | 20 | ||
| 21 | @Bean | 21 | @Bean |
| 22 | - public BeanPostProcessor objectMapperBeanPostProcessor() { | ||
| 23 | - return new BeanPostProcessor() { | ||
| 24 | - | ||
| 25 | - @Override | ||
| 26 | - public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException { | ||
| 27 | - if (!(bean instanceof ObjectMapper)) { | ||
| 28 | - return bean; | ||
| 29 | - } | ||
| 30 | - ObjectMapper objectMapper = (ObjectMapper) bean; | ||
| 31 | - SimpleModule simpleModule = new SimpleModule(); | ||
| 32 | - /* | ||
| 33 | - * 1. 新增Long类型序列化规则,数值超过2^53-1,在JS会出现精度丢失问题,因此Long自动序列化为字符串类型 | ||
| 34 | - * 2. 新增LocalDateTime序列化、反序列化规则 | ||
| 35 | - */ | ||
| 36 | - simpleModule | ||
| 37 | - .addSerializer(Long.class, NumberSerializer.INSTANCE) | ||
| 38 | - .addSerializer(Long.TYPE, NumberSerializer.INSTANCE) | ||
| 39 | - .addSerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE) | ||
| 40 | - .addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE); | ||
| 41 | - | ||
| 42 | - objectMapper.registerModules(simpleModule); | ||
| 43 | - | ||
| 44 | - JsonUtils.init(objectMapper); | ||
| 45 | - log.info("初始化 jackson 自动配置"); | ||
| 46 | - return bean; | ||
| 47 | - } | ||
| 48 | - }; | 22 | + @SuppressWarnings("InstantiationOfUtilityClass") |
| 23 | + public JsonUtils jsonUtils(List<ObjectMapper> objectMappers) { | ||
| 24 | + // 1.1 创建 SimpleModule 对象 | ||
| 25 | + SimpleModule simpleModule = new SimpleModule(); | ||
| 26 | + simpleModule | ||
| 27 | + // 新增 Long 类型序列化规则,数值超过 2^53-1,在 JS 会出现精度丢失问题,因此 Long 自动序列化为字符串类型 | ||
| 28 | + .addSerializer(Long.class, NumberSerializer.INSTANCE) | ||
| 29 | + .addSerializer(Long.TYPE, NumberSerializer.INSTANCE) | ||
| 30 | + // 新增 LocalDateTime 序列化、反序列化规则 | ||
| 31 | + .addSerializer(LocalDateTime.class, LocalDateTimeSerializer.INSTANCE) | ||
| 32 | + .addDeserializer(LocalDateTime.class, LocalDateTimeDeserializer.INSTANCE); | ||
| 33 | + // 1.2 注册到 objectMapper | ||
| 34 | + objectMappers.forEach(objectMapper -> objectMapper.registerModule(simpleModule)); | ||
| 35 | + | ||
| 36 | + // 2. 设置 objectMapper 到 JsonUtils { | ||
| 37 | + JsonUtils.init(CollUtil.getFirst(objectMappers)); | ||
| 38 | + log.info("[init][初始化 JsonUtils 成功]"); | ||
| 39 | + return new JsonUtils(); | ||
| 49 | } | 40 | } |
| 50 | 41 | ||
| 51 | } | 42 | } |
yudao-server/src/main/resources/application-local.yaml
| @@ -156,9 +156,12 @@ logging: | @@ -156,9 +156,12 @@ logging: | ||
| 156 | cn.iocoder.yudao.module.bpm.dal.mysql: debug | 156 | cn.iocoder.yudao.module.bpm.dal.mysql: debug |
| 157 | cn.iocoder.yudao.module.infra.dal.mysql: debug | 157 | cn.iocoder.yudao.module.infra.dal.mysql: debug |
| 158 | cn.iocoder.yudao.module.infra.dal.mysql.job.JobLogMapper: INFO # 配置 JobLogMapper 的日志级别为 info | 158 | cn.iocoder.yudao.module.infra.dal.mysql.job.JobLogMapper: INFO # 配置 JobLogMapper 的日志级别为 info |
| 159 | + cn.iocoder.yudao.module.infra.dal.mysql.file.FileConfigMapper: INFO # 配置 FileConfigMapper 的日志级别为 info | ||
| 159 | cn.iocoder.yudao.module.pay.dal.mysql: debug | 160 | cn.iocoder.yudao.module.pay.dal.mysql: debug |
| 160 | cn.iocoder.yudao.module.pay.dal.mysql.notify.PayNotifyTaskMapper: INFO # 配置 JobLogMapper 的日志级别为 info | 161 | cn.iocoder.yudao.module.pay.dal.mysql.notify.PayNotifyTaskMapper: INFO # 配置 JobLogMapper 的日志级别为 info |
| 161 | cn.iocoder.yudao.module.system.dal.mysql: debug | 162 | cn.iocoder.yudao.module.system.dal.mysql: debug |
| 163 | + cn.iocoder.yudao.module.system.dal.mysql.sensitiveword.SensitiveWordMapper: INFO # 配置 SensitiveWordMapper 的日志级别为 info | ||
| 164 | + cn.iocoder.yudao.module.system.dal.mysql.sms.SmsChannelMapper: INFO # 配置 SmsChannelMapper 的日志级别为 info | ||
| 162 | cn.iocoder.yudao.module.tool.dal.mysql: debug | 165 | cn.iocoder.yudao.module.tool.dal.mysql: debug |
| 163 | cn.iocoder.yudao.module.member.dal.mysql: debug | 166 | cn.iocoder.yudao.module.member.dal.mysql: debug |
| 164 | cn.iocoder.yudao.module.trade.dal.mysql: debug | 167 | cn.iocoder.yudao.module.trade.dal.mysql: debug |