Eddy
Eddy

Reputation: 1802

How to inject ProducerTemplate

I'm wondering how to properly use the @Produce annotation for a ProducerTemplate I have defined in one of my model beans.

If I add an @Autowired and this @Bean definition everything is peachy:

    @Bean
    ProducerTemplate producerTemplate() throws Exception {
        ProducerTemplate producerTemplate = camelContext().createProducerTemplate();
        producerTemplate.setDefaultEndpointUri("seda:workflowEntryPoint");
        return producerTemplate;
    }

But if I don't and only do

    @Produce(uri = "seda:workflowEntryPoint")
    private ProducerTemplate producer;

I get an NPE when trying to use it to call sendMessage(). So, what's the correct usage of the annotation?

Best, Edoardo

Upvotes: 1

Views: 3860

Answers (1)

Hussain Pirosha
Hussain Pirosha

Reputation: 1376

As per camel's documentation , it creates a proxy implementing the interface that has been annotated with @Produce. Can you try to have a very simple interface with just one method as suggested in the documentation. Although, your code should work but I am suspecting that the ProducerTemplate has plenty of methods and bcoz of that the proxy creation does not happen

Upvotes: 1

Related Questions