Java RabbitMQ MessageConverter在运行Spring启动应用程序时出现错误

Java RabbitMQ MessageConverter在运行Spring启动应用程序时出现错误,java,spring,maven,spring-boot,rabbitmq,Java,Spring,Maven,Spring Boot,Rabbitmq,我正在尝试运行spring启动应用程序1.4.7.RELEASE,它将向RabbitMQ队列吐出消息。我的构建工作成功,但当我试图通过mvn clean spring boot:run运行应用程序时,我在文件ProduceMessage.java中遇到以下错误 @PropertySource("classpath:application.properties") @Component @ContextConfiguration("classpath:META-INF/spring/rabbitm

我正在尝试运行spring启动应用程序1.4.7.RELEASE,它将向RabbitMQ队列吐出消息。我的构建工作成功,但当我试图通过mvn clean spring boot:run运行应用程序时,我在文件ProduceMessage.java中遇到以下错误

@PropertySource("classpath:application.properties")
@Component
@ContextConfiguration("classpath:META-INF/spring/rabbitmq-producer.xml")
public class ProduceMessage {

    private static final Logger logger = LoggerFactory.getLogger(ProduceMessage.class.getName());

    @Autowired
    private RabbitTemplate myEventTemplate;

    @Autowired
    private MessageConverter ctdMessageConverter;

    @Value("${fieldChangedEvent.MainQueue}")
    private String mainQ;

    /*
     * (non-Javadoc)
     * 
     * @see com.ge.predix.dispatcherqproducer.api.produceFieldChangedEvent#
     * produceFieldChangedEvent(com.ge.dsp.pm.solution.service.fieldchanged.
     * FieldChangedEvent)
     */
    public boolean produceStringMessage(String data) {

        logger.debug("In produceStringMessage......");

        MessageProperties prop = new MessageProperties();
        prop.setContentType(MessageProperties.CONTENT_TYPE_TEXT_PLAIN);

        Message msg = ctdMessageConverter.toMessage(data, prop);

        logger.debug("publishing string to ......= " + mainQ);
        myEventTemplate.convertAndSend(mainQ, msg);

        return true;
    }
}
错误:

2017-10-04 11:06:08.830[0;39m[32m信息[0;39m[35m62162[0;39m[2m--[0;39m[2m]主站][0;39m[36mo.apache.catalina.core.StandardService[0;39m[2m][0;39m停止服务[Tomcat] [2m2017-10-04 11:06:08.849[0;39m[32m信息[0;39m[35m62162[0;39m[2m--[0;39m[2m[main][0;39m[36MUTOConfiguration ReportLoggingInitializer[0;39m[0;39m]

启动ApplicationContext时出错。若要显示自动配置报告,请在启用“调试”的情况下重新运行应用程序

[2m2017-10-04 11:06:08.944[0;39m[31mERROR[0;39m[35m62162[0;39m[2m--[0;39m[2m]主站][0;39m[36mo.s.b.d.日志故障分析报告员[0;39m[2m[0;39m]

***************************应用程序无法启动*************************** 说明: com.ge.power.tcs.producer.ProduceMessage中的字段ctdMessageConverter需要类型为的bean 'org.springframework.amqp.support.converter.MessageConverter'表示 找不到

行动:

考虑定义类型为的bean 您的应用程序中的“org.springframework.amqp.support.converter.MessageConverter” 配置

rabbitmq-producer.xml

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:rabbit="http://www.springframework.org/schema/rabbit"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:oxm="http://www.springframework.org/schema/oxm"
    xsi:schemaLocation="http://www.springframework.org/schema/rabbit
           http://www.springframework.org/schema/rabbit/spring-rabbit.xsd
           http://www.springframework.org/schema/beans
           http://www.springframework.org/schema/beans/spring-beans.xsd
           http://www.springframework.org/schema/oxm http://www.springframework.org/schema/oxm/spring-oxm.xsd">
    <bean id="ctdMessageConverter"
        class="org.springframework.amqp.support.converter.ContentTypeDelegatingMessageConverter">
        <property name="delegates">
            <map>
                <entry key="text/plain" value-ref="simpleMessageConverter" />
            </map>
        </property>
    </bean> 
    <bean id="simpleMessageConverter"
        class="org.springframework.amqp.support.converter.SimpleMessageConverter" />          
 </beans>

当我们在spring boot的主应用程序类中提到@ImportResourceclasspath:META-INF/spring/rabbitmq-producer.xml,而不是包含bean实例化的@ContextConfigurationclasspath:META-INF/spring/rabbitmq-producer.xml时,问题就解决了,您是否有要注入的消息转换器的@bean定义这里?它是import org.springframework.amqp.support.converter.MessageConverter;实例我的问题是,您到底希望在这里注入什么,为什么是您的期望?这在您共享的代码中并不明显。@sromit autoconfiguration不提供MessageConverter类型的bean,如果您是自动连接,那么您必须使用c创建edwin提到的MessageConverter类型的bean。如何创建MessageConverter类型的bean?