骆驼producerTemplate没有Spring MVC中注入 [英] Camel producerTemplate is not injected in spring MVC
问题描述
我使用Spring MVC和骆驼在我的项目,但遇到的一个问题是,producerTemplate不能自动装配。请在下面检查细节,
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,
文件web.xml中:
File web.xml:
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>
文件ispatcher-servlet.xml中
File ispatcher-servlet.xml
<import resource="camel-config.xml"/>
文件骆驼-config.xml中,定义camelContext
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>
这是我的Java类:
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?
推荐答案
您可能需要确保CammelConnectorImp是一个已知的bean来春。
You probably need to make sure CammelConnectorImp is a known bean to Spring.
@Bean
public class CamelConnectorImp{ ..
(更新:)
您也许应该扫描该POJO为好,从而使@Bean被拾起:
You should probably scan for this pojo as well, so that the @Bean gets picked up:
<context:component-scan base-package="com.myproject.camel.routes,com.myproject.connector.camel"/>
或类似可能会帮助一些东西。
or something similar will probably help.
这篇关于骆驼producerTemplate没有Spring MVC中注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!