I’m having a simple MessageProducer class that sends messages to a direct channel using camel’s ProducerTemplate
Here is the code
@Component
@Slf4j
public class MessageProducer {
@EndpointInject(uri = "direct:app.out")
protected ProducerTemplate template;
public void sendEvent(Object payload, String eventName) {
Map<String, Object> headers = new HashMap<String, Object>();
headers.put("eventName", eventName);
template.sendBodyAndHeaders(payload, headers);
log.debug("Sent message {}", payload);
}
}
When I debug this I found template to be null when this runs in a webapp, but it works in a spring Junit test.
I can’t understand whats gone wrong.
Yeah the spring bean post processor needs to kick in, to let the IoC run. The Camel Test Kit does this automatic and hence why it works from unit tests.