骆驼生产者模板未在spring MVC中注入 [英] Camel producerTemplate is not injected in spring MVC

查看:29
本文介绍了骆驼生产者模板未在spring MVC中注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在我的项目中使用 Spring MVC 和 Camel,但遇到了 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"/>

文件camel-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 是 Spring 的已知 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.

这篇关于骆驼生产者模板未在spring MVC中注入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆