简体   繁体   English

运行Spring Boot应用程序时RabbitMQ MessageConverter提供错误

[英]RabbitMQ MessageConverter giving error when running Spring Boot app

I am trying to run a spring boot app (1.4.7.RELEASE) which will spit out message to a RabbitMQ queue. 我正在尝试运行一个Spring Boot应用程序(1.4.7.RELEASE),它将把消息吐出到RabbitMQ队列。 My build works successfully but when I am trying to run the app by mvn clean spring-boot:run , I am getting the following error in the file ProduceMessage.java 我的构建成功完成,但是当我尝试通过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;
    }
}

The error : 错误 :

2017-10-04 11:06:08.830[0;39m [32m INFO[0;39m [35m62162[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.apache.catalina.core.StandardService [0;39m [2m:[0;39m Stopping service [Tomcat] [2m2017-10-04 11:06:08.849[0;39m [32m INFO[0;39m [35m62162[0;39m [2m---[0;39m [2m[ main][0;39m [36mutoConfigurationReportLoggingInitializer[0;39m [2m:[0;39m 2017-10-04 11:06:08.830 [0; 39m [32m INFO [0; 39m [35m62162 [0; 39m [2m --- [0; 39m [2m [main]] [0; 39m [36mo.apache。 catalina.core.StandardService [0; 39m [2m:[0; 39m正在停止服务[Tomcat] [2m2017-10-04 11:06:08.849 [0; 39m [32m INFO [0; 39m [35m62162 [0; 39m [ 2m --- [0; 39m [2m [main] [0; 39m [36mutoConfigurationReportLoggingInitializer [0; 39m [2m:[0; 39m

Error starting ApplicationContext. 启动ApplicationContext时出错。 To display the auto-configuration report re-run your application with 'debug' enabled. 要显示自动配置报告,请在启用“调试”的情况下重新运行您的应用程序。

[2m2017-10-04 11:06:08.944[0;39m [31mERROR[0;39m [35m62162[0;39m [2m---[0;39m [2m[ main][0;39m [36mo.sbdLoggingFailureAnalysisReporter [0;39m [2m:[0;39m [2m2017-10-04 11:06:08.944 [0; 39m [31mERROR [0; 39m [35m62162 [0; 39m [2m --- [0; 39m [2m [main] [0; 39m [36mo.sbdLoggingFailureAnalysisReporter [ 0; 39m [2m:[0; 39m

*************************** APPLICATION FAILED TO START *************************** Description: Field ctdMessageConverter in com.ge.power.tcs.producer.ProduceMessage required a bean of type 'org.springframework.amqp.support.converter.MessageConverter' that could not be found. ***************************应用程序无法启动******************* ********说明:com.ge.power.tcs.producer.ProduceMessage中的字段ctdMessageConverter需要一个类型为'org.springframework.amqp.support.converter.MessageConverter'的bean。

Action: 行动:

Consider defining a bean of type 'org.springframework.amqp.support.converter.MessageConverter' in your configuration. 考虑在配置中定义类型为“ org.springframework.amqp.support.converter.MessageConverter”的bean。


rabbitmq-producer.xml 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的主Application类中提到@ImportResource("classpath:META-INF/spring/rabbitmq-producer.xml")而不是@ContextConfiguration("classpath:META-INF/spring/rabbitmq-producer.xml") ,其中包含Bean实例化

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM