Error Injecting endpoint into a bean in Camel

114 views Asked by At

I have a bean defined with the annotation.I tried using CamelBeanPostProcessor but the camelContext is null.

public class HelloWorld {

  @EndpointInject(uri="direct:copy")
  private ProducerTemplate template;


  public final void speak(Exchange e) {
    template.sendBody("A new message");
  }

  public ProducerTemplate getTemplate() {
    return template;
  }

  public void setTemplate(ProducerTemplate template) {
    this.template = template;
  }

}
1

There are 1 answers

0
Ramin Arabbagheri On

There are quite a lot of ways of achieving this. As your bean is a processor, you can simply implement Processor and then have access to the entire exchange, and of course camelcontext as well:

public class HelloWorld implements Processor {
  public void process(Exchange exchange) throws Exception {
    context = exchange.getContext()
  }
}