1
votes

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...

1
Run your Boot app with --debug to see the auto-configuration report.Gary Russell
to long to add it pastebin.com/VRGkvExuAlexandre
Just adding activemq-broker works... i misunderstood JMS >_<Alexandre
can you post your working code? mine is still not workingSayantan
You must add a bean jmstemplateAlexandre

1 Answers

1
votes

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;
}