2
votes

I use Apache Camel for a projet and I would like to use the produce annotation to send an object in a file. First, is it possible ? Is there a better way ?

Secondly, I tried this snippet code:

public class MyProducer {

  private static final String MEDIA = "file:";

  private static final String PATH = "c:/directory";

  @Produce(uri = MEDIA + PATH)
  protected ProducerTemplate producer;

  public void publish(MyObject o) {
    producer.sendBody(o);
  }
}

When I call the publish methode the producer is not inject (null). Anybody have an idea ? Thanks in advance.

1

1 Answers

2
votes

It depends on how you create the MyProducer class. You have to define it inside a spring context as a spring bean to make the annotations work.