From 1d239c98776b22d055550a8b4db708e3d974efd7 Mon Sep 17 00:00:00 2001 From: YunaiV Date: Tue, 16 Apr 2024 09:17:11 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BF=AE=E6=94=B9=20rabbitmq=20=E5=BA=8F?= =?UTF-8?q?=E5=88=97=E5=8C=96=E6=96=B9=E5=BC=8F=EF=BC=8C=E4=BD=BF=E7=94=A8?= =?UTF-8?q?=20Jackson2JsonMessageConverter=20=E6=9B=BF=E4=BB=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../YudaoRabbitMQAutoConfiguration.java | 19 +++++++++---------- 1 file changed, 9 insertions(+), 10 deletions(-) diff --git a/yudao-framework/yudao-spring-boot-starter-mq/src/main/java/cn/iocoder/yudao/framework/mq/rabbitmq/config/YudaoRabbitMQAutoConfiguration.java b/yudao-framework/yudao-spring-boot-starter-mq/src/main/java/cn/iocoder/yudao/framework/mq/rabbitmq/config/YudaoRabbitMQAutoConfiguration.java index 770c50ff7..af1467376 100644 --- a/yudao-framework/yudao-spring-boot-starter-mq/src/main/java/cn/iocoder/yudao/framework/mq/rabbitmq/config/YudaoRabbitMQAutoConfiguration.java +++ b/yudao-framework/yudao-spring-boot-starter-mq/src/main/java/cn/iocoder/yudao/framework/mq/rabbitmq/config/YudaoRabbitMQAutoConfiguration.java @@ -1,12 +1,11 @@ package cn.iocoder.yudao.framework.mq.rabbitmq.config; -import cn.hutool.core.util.ReflectUtil; import lombok.extern.slf4j.Slf4j; -import org.springframework.amqp.utils.SerializationUtils; +import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter; +import org.springframework.amqp.support.converter.MessageConverter; import org.springframework.boot.autoconfigure.AutoConfiguration; import org.springframework.boot.autoconfigure.condition.ConditionalOnClass; - -import java.lang.reflect.Field; +import org.springframework.context.annotation.Bean; /** * RabbitMQ 消息队列配置类 @@ -18,12 +17,12 @@ import java.lang.reflect.Field; @ConditionalOnClass(name = "org.springframework.amqp.rabbit.core.RabbitTemplate") public class YudaoRabbitMQAutoConfiguration { - static { - // 强制设置 SerializationUtils 的 TRUST_ALL 为 true,避免 RabbitMQ Consumer 反序列化消息报错 - // 为什么不通过设置 spring.amqp.deserialization.trust.all 呢?因为可能在 SerializationUtils static 初始化后 - Field trustAllField = ReflectUtil.getField(SerializationUtils.class, "TRUST_ALL"); - ReflectUtil.removeFinalModify(trustAllField); - ReflectUtil.setFieldValue(SerializationUtils.class, trustAllField, true); + /** + * Jackson2JsonMessageConverter Bean:使用 jackson 序列化消息 + */ + @Bean + public MessageConverter createMessageConverter() { + return new Jackson2JsonMessageConverter(); } }