【ActiveMQ】消息生產者自動註入報錯:Could not autowire. No beans of 'JmsMessagingTemplate' type found
阿新 • • 發佈:2017-11-29
註入 fin producer 定義 red because spl send code
使用ActiveMQ過程中,定義消息生產者:
package com.sxd.jms.producer; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.jms.core.JmsMessagingTemplate; import org.springframework.stereotype.Service; import javax.jms.Destination; @Service("producer") public class Producer1 { @AutowiredView Code// 也可以註入JmsTemplate,JmsMessagingTemplate對JmsTemplate進行了封裝 private JmsMessagingTemplate jmsTemplate; // 發送消息,destination是發送到的隊列,message是待發送的消息 public void sendMessage(Destination destination, final String message){ jmsTemplate.convertAndSend(destination, message); } }
但是IDE報錯:
啟動編譯,依舊是報錯:
Description: Field jmsTemplate in com.sxd.jms.producer.Producer1 required a bean of type ‘org.springframework.jms.core.JmsMessagingTemplate‘ that could not be found. - Bean method ‘jmsMessagingTemplate‘ not loaded because Ancestor org.springframework.boot.autoconfigure.jms.JmsAutoConfiguration did not match Action: Consider revisiting the conditions above or defining a bean of type‘org.springframework.jms.core.JmsMessagingTemplate‘ in your configuration.
解決方式:
因為application.properties中配置ActiveMQ的相關配置後面有空格:
把配置後面的空格去掉。保存,重新編譯。
解決了!!!!
【ActiveMQ】消息生產者自動註入報錯:Could not autowire. No beans of 'JmsMessagingTemplate' type found