gpt4 book ai didi

spring - Camel producerTemplate 未在 spring MVC 中注入(inject)

转载 作者:行者123 更新时间:2023-12-01 15:53:10 26 4
gpt4 key购买 nike

我在我的项目中使用了 Spring MVC 和 Camel,但遇到了 producerTemplate 无法 Autowiring 的问题。请检查下面的详细信息,

文件 web.xml:

<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/dispatcher-servlet.xml</param-value>
</context-param>

文件ispatcher-servlet.xml

<import resource="camel-config.xml"/>

文件camel-config.xml,定义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 类:

package com.myproject.connector.camel;
public class CamelConnectorImp{
@Autowired
private ProducerTemplate producerTemplate; //This is null after starting
producerTemplate.requestBodyAndHeaders(serviceEndpoint,request, headers);
...
}

有人可以指出我做错了什么吗?

最佳答案

您可能需要确保 CammelConnectorImp 是 Spring 的已知 bean。

@Bean
public class CamelConnectorImp{ ..

(更新:)

您可能还应该扫描这个 pojo,以便找到 @Bean:

<context:component-scan base-package="com.myproject.camel.routes,com.myproject.connector.camel"/> 

或类似的东西可能会有所帮助。

关于spring - Camel producerTemplate 未在 spring MVC 中注入(inject),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13265703/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com