fix(rabbitmq): 修复Spring Boot启动时objectMapper bean冲突
- 取消了RabbitMQConfig中通过方法参数注入ObjectMapper,避免重复定义bean - 在messageConverter方法内新建ObjectMapper实例,独立配置序列化选项 - 在application.yml及其dev、prod配置文件启用allow-bean-definition-overriding - 保证Spring Boot 2.5.15环境中bean定义覆盖正常,解决启动失败问题 - 修复后确保MQ消息队列和扫码登录功能正常运行
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
package com.gxwebsoft.common.mq.config;
|
||||
|
||||
import com.fasterxml.jackson.databind.DeserializationFeature;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
import com.fasterxml.jackson.databind.SerializationFeature;
|
||||
import com.fasterxml.jackson.datatype.jsr310.JavaTimeModule;
|
||||
@@ -67,15 +68,13 @@ public class RabbitMQConfig {
|
||||
// ==================== Message Converter ====================
|
||||
|
||||
@Bean
|
||||
public ObjectMapper objectMapper() {
|
||||
public MessageConverter messageConverter() {
|
||||
// 使用JacksonConfig中定义的@Primary objectMapper bean
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
objectMapper.registerModule(new JavaTimeModule());
|
||||
objectMapper.disable(SerializationFeature.WRITE_DATES_AS_TIMESTAMPS);
|
||||
return objectMapper;
|
||||
}
|
||||
|
||||
@Bean
|
||||
public MessageConverter messageConverter(ObjectMapper objectMapper) {
|
||||
objectMapper.disable(SerializationFeature.WRITE_DATE_TIMESTAMPS_AS_NANOSECONDS);
|
||||
objectMapper.configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false);
|
||||
return new Jackson2JsonMessageConverter(objectMapper);
|
||||
}
|
||||
|
||||
|
||||
@@ -4,6 +4,7 @@
|
||||
spring:
|
||||
main:
|
||||
allow-circular-references: true
|
||||
allow-bean-definition-overriding: true # 允许bean定义覆盖,解决RabbitMQConfig中的objectMapper bean冲突
|
||||
datasource:
|
||||
url: jdbc:mysql://47.119.165.234:13308/gxwebsoft_core?useSSL=false&serverTimezone=UTC
|
||||
username: gxwebsoft_core
|
||||
|
||||
@@ -8,6 +8,10 @@ spring:
|
||||
password: jdj7HYEdYHnYEFBy
|
||||
driver-class-name: com.mysql.cj.jdbc.Driver
|
||||
type: com.alibaba.druid.pool.DruidDataSource
|
||||
|
||||
# 允许bean定义覆盖,解决RabbitMQConfig和JacksonConfig中的objectMapper bean冲突
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
redis:
|
||||
database: 0
|
||||
host: 1Panel-redis-Q1LE
|
||||
|
||||
@@ -11,6 +11,10 @@ spring:
|
||||
|
||||
application:
|
||||
name: server
|
||||
|
||||
# 允许bean定义覆盖,解决RabbitMQConfig和JacksonConfig中的objectMapper bean冲突
|
||||
main:
|
||||
allow-bean-definition-overriding: true
|
||||
|
||||
# 连接池配置
|
||||
datasource:
|
||||
|
||||
Reference in New Issue
Block a user