I have a requirement to integrate Camel with spring-boot , to achieve same I am using below code to build ProducerTemplate
for bean integration but ProducerTemplate
will always NULL.
Java Code
@RestController
public class TestController implements ProductSummaryApi {
@EndpointInject(uri = "direct:test")
ProducerTemplate testRoute;
@RequestMapping(value = "/v1/test", method = RequestMethod.GET)
public String test(){
System.out.println("Route: " + testRoute);
return "Test";
}
}
Line System.out.println("Route: " + testRoute);
prints NULL
pom.xml
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-spring-boot-starter</artifactId>
<version>2.21.0</version>
</dependency>
Any hint appreciated, why the application is not able to build ProducerTemplate
object.
ProducerTemplate
from spring boot camel, @Produce
relies on Spring for dependency injection of Producer template. Which means that the service that autowires the producer template must register itself as the bean. @Component
or it's sub-types. ProducerTemplate
and have associated with a context(assuming you have registered as bean using @Bean
), use @Produce(context="contextName1")
. Check your component scan path. That's mostly your issue.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.