Apache Camel POJO Bean 处理器单例还是原型? [英] Apache Camel POJO Bean Processor Singleton or Prototype?
问题描述
我正在使用 Camel 的 spring DSL 来构建路由,并且我正在使用我的 POJO bean 作为处理器.
I'm using Camel's spring DSL to build routes and I'm using my POJO bean as a processor.
最初,我在做:
<bean ref="myPojoBeanProcessor"/>
其中,myPojoBeanProcessor"在我的 spring 上下文中被定义为一个 bean.
where, 'myPojoBeanProcessor' was defined as a bean in my spring context.
然后,我切换到:
<bean beanType="com.mycompany.transformation.MyPojoBeanProcessor"/>
我认为 Java DSL 等价物是:
The Java DSL equivalent would be, I think:
from("xxx").bean(MyPojoBeanProcessor.class).xxx
我想知道后一种方法是否会在每个请求中实例化一个 bean 对象,或者是否将 bean 实例缓存并用作单例(就像 spring 中的默认值一样).
I'm wondering if with the later approach, a bean object would be instantiated with every request or would the bean instance be cached and used as a singleton (like the default in spring).
我无法在骆驼文档或谷歌上找到答案.有人知道这个问题的答案吗?
I was unable to find an answer in the camel documentation or on google. Does anyone know the answer to this question?
推荐答案
你为什么不试试看:)
Camel 将使用默认的无参数构造函数创建一个实例,并缓存该实例,例如它的单例范围.
Camel will create an instance one time using the default no-arg constructor, and cache the instance, eg its singleton scoped.
这篇关于Apache Camel POJO Bean 处理器单例还是原型?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!