8.2. 使用带有构造器的 Bean
当您要使用构造器参数创建 Bean 时,从 Camel 4.1 开始,您可以将它们添加为 XML 标签。例如:
Camel 4.1+: Beans 带有 构造器 标签
<camel>
<bean name="beanFromProps" type="com.acme.MyBean">
<constructors>
<constructor index="0" value="true"/>
<constructor index="1" value="Hello World"/>
</constructors>
<!-- and you can still have properties -->
<properties>
<property key="field1" value="f1_p" />
<property key="field2" value="f2_p" />
<property key="nested.field1" value="nf1_p" />
<property key="nested.field2" value="nf2_p" />
</properties>
</bean>
</camel>
如果使用 Camel 4.0,则必须在 type 属性中放入 constructor 参数:
Camel 4.0:在 type 属性中使用 构造器 参数的 Beans
<bean name="beanFromProps" type="com.acme.MyBean(true, 'Hello World')">
<properties>
<property key="field1" value="f1_p" />
<property key="field2" value="f2_p" />
<property key="nested.field1" value="nf1_p" />
<property key="nested.field2" value="nf2_p" />
</properties>
</bean>