我正在尝试从我的应用程序中用JMS发送一条消息。
我加进我的水里
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
</dependency>
<dependency>
<groupId>javax.jms</groupId>
<artifactId>jms</artifactId>
<version>1.1</version>
</dependency>春天就要开始了
JmsTemplate和ConnectionFactory是由Spring自动创建的。在本例中,ActiveMQ代理运行嵌入式。
在我的批次作家里
@Autowired
JmsTemplate jmsTemplate,
void writer(List<String> items) {
jmsTemplate.convertAndSend(items);
}但是没有找到bean JmsTemplate。
没有“org.springframework.jms.core.JmsTemplate”类型的合格bean可用:预期至少有一个可作为自动测试候选的bean
我试图在@配置中添加一个消息转换器
@Bean
public MessageConverter jacksonJmsMessageConverter() {
MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
converter.setTargetType(MessageType.TEXT);
converter.setTypeIdPropertyName("_type");
return converter;
}我尝试添加@EnableJMS (即使它只是用于侦听器.)
但这行不通..。
我不明白为什么,在教程里看起来很容易.
发布于 2019-06-04 07:58:46
要工作,我们需要创建一个jmsTemplate bean
@Bean
public ConnectionFactory getConnectionFactory() {
TibjmsConnectionFactory connectionFactory = new TibjmsConnectionFactory(urlBrocker);
return connectionFactory;
}
@Bean
public JmsTemplate jmsTemplate() {
JmsTemplate template = new JmsTemplate();
template.setConnectionFactory(getConnectionFactory());
template.setPubSubDomain(false); // false for a Queue, true for a Topic
return template;
}https://stackoverflow.com/questions/55243499
复制相似问题