记录工作中遇到的问题内容比较简陋,如有不懂可以私信,上班期间都是在得
RabbitMq发消息包名不一致报错,配置文件增加消息转换器配置
package com.mingqi.config;
import com.rabbitmq.client.ConnectionFactory;
import lombok.extern.slf4j.Slf4j;
import org.springframework.amqp.rabbit.config.SimpleRabbitListenerContainerFactory;
import org.springframework.amqp.support.converter.DefaultJackson2JavaTypeMapper;
import org.springframework.amqp.support.converter.Jackson2JsonMessageConverter;
import org.springframework.amqp.support.converter.MessageConverter;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
/**
* amqp配置
*
* @author XHao
* @date 2022-10-29 19:07
*/
@Configuration
@Slf4j
public class AmqpConfig {
@Bean
public Jackson2JsonMessageConverter messageConverter() {
Jackson2JsonMessageConverter converter = new Jackson2JsonMessageConverter();
DefaultJackson2JavaTypeMapper typeMapper = new DefaultJackson2JavaTypeMapper();
typeMapper.setTrustedPackages("*");
converter.setJavaTypeMapper(typeMapper);
return converter;
}
}