Camel producerTemplate未在spring MVC中注入

编程入门 行业动态 更新时间:2024-10-22 07:58:49
本文介绍了Camel producerTemplate未在spring MVC中注入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

限时送ChatGPT账号..

我在我的项目中使用 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/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.

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

更多推荐

[db:关键词]

本文发布于:2023-04-19 22:08:10,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/971437.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:producerTemplate   Camel   MVC   spring

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!