Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/387.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 骆驼及;spring忽略@product和@EndpointInject_Java_Spring_Messaging_Apache Camel - Fatal编程技术网

Java 骆驼及;spring忽略@product和@EndpointInject

Java 骆驼及;spring忽略@product和@EndpointInject,java,spring,messaging,apache-camel,Java,Spring,Messaging,Apache Camel,我有一个简单的MessageProducer类,它使用camel的ProducerTemplate 这是密码 @Component @Slf4j public class MessageProducer { @EndpointInject(uri = "direct:app.out") protected ProducerTemplate template; public void sendEvent(Object payload, String eventName)

我有一个简单的
MessageProducer
类,它使用camel的
ProducerTemplate

这是密码

@Component
@Slf4j
public class MessageProducer {

    @EndpointInject(uri = "direct:app.out")
    protected ProducerTemplate template;

    public void sendEvent(Object payload, String eventName) {
        Map<String, Object> headers = new HashMap<String, Object>();
        headers.put("eventName", eventName);

        template.sendBodyAndHeaders(payload, headers);

        log.debug("Sent message {}", payload);
    }

}
@组件
@Slf4j
公共类消息生成器{
@EndpointInject(uri=“direct:app.out”)
受保护的产品模板;
public void sendEvent(对象负载、字符串eventName){
Map headers=newhashmap();
headers.put(“eventName”,eventName);
template.sendboyandheaders(有效负载、头);
调试(“发送消息{}”,有效载荷);
}
}
当我调试这个模板时,我发现它在webapp中运行时为null,但它在springjunit测试中工作


我不明白出了什么问题。

是的,SpringBean后处理器需要启动,让IoC运行。驼峰测试套件自动完成这项工作,因此它可以从单元测试中工作。

可能是一个愚蠢的问题,但是您是否扫描组件,以便让MessageProducer类由spring拾取并初始化?是的,spring bean后处理器需要启动,以便让IoC运行。驼峰测试套件自动完成这项工作,因此它可以从单元测试中工作。@Claus,你说得对,添加一个后处理器完成了这项工作。这个问题可以标记为已回答吗?@Claus,需要有一个答案才能将其标记为已回答:)你能详细说明怎么做吗。?我创建了一个新的spring beanpostprocessor,但是我需要在其中做什么呢。