I’m using Spring MVC and Camel in my project, but encountering an issue that the producerTemplate is not able to be Autowired. Please check details below,
File web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
File ispatcher-servlet.xml
<import resource="camel-config.xml"/>
File camel-config.xml, define camelContext
<context:component-scan base-package="com.myproject.camel.routes"/>
<camelContext xmlns="http://camel.apache.org/schema/spring" id="myproject.camel">
<contextScan/>
<template id="producerTemplate"/>
</camelContext>
And here is my JAVA class:
package com.myproject.connector.camel;
public class CamelConnectorImp{
@Autowired
private ProducerTemplate producerTemplate; //This is null after starting
producerTemplate.requestBodyAndHeaders(serviceEndpoint,request, headers);
...
}
Can someone point out what I’m doing wrong please?
You probably need to make sure CammelConnectorImp is a known bean to Spring.
(Update:)
You should probably scan for this pojo as well, so that the @Bean gets picked up:
or something similar will probably help.