Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring Boot JMS No JmsTemplate bean available

I'm trying to send a message with JMS from my application.

I add in my pom

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-jms</artifactId>
    </dependency>
    <dependency>
        <groupId>javax.jms</groupId>
        <artifactId>jms</artifactId>
        <version>1.1</version>
    </dependency>

The spring getting started say

JmsTemplate and ConnectionFactory are created automatically by Spring Boot. In this case, the ActiveMQ broker runs embedded.

and in my batch writer

@Autowired
JmsTemplate jmsTemplate,

void writer(List<String> items) {
   jmsTemplate.convertAndSend(items);
}

But the bean JmsTemplate is not found

No qualifying bean of type 'org.springframework.jms.core.JmsTemplate' available: expected at least 1 bean which qualifies as autowire candidate

I tried to add an message converter in the @configuration

@Bean
public MessageConverter jacksonJmsMessageConverter() {
    MappingJackson2MessageConverter converter = new MappingJackson2MessageConverter();
    converter.setTargetType(MessageType.TEXT);
    converter.setTypeIdPropertyName("_type");
    return converter;
}

I tried to add the @EnableJMS (even if it's just for listener...)

But it dosen't work...

I don't understand why, on tutorials it looks like easy...

like image 262
Alexandre Avatar asked Oct 14 '25 03:10

Alexandre


1 Answers

To work we need to create a 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;
}
like image 53
Alexandre Avatar answered Oct 18 '25 21:10

Alexandre



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!