43.5. Java DSL Bean 语法

Java DSL 为 Bean 组件提供 syntactic sugar。您可以使用下列语法,而不明确指定 bean 作为端点(例如 to ("bean:beanName")

// Send message to the bean endpoint
// and invoke method resolved using Bean Binding.
from("direct:start").beanRef("beanName");

// Send message to the bean endpoint
// and invoke given method.
from("direct:start").beanRef("beanName", "methodName");

您可以指定 bean 本身,而不传递对 bean 的引用名称(这样 Camel 将会在 registry 中查找该文件):

// Send message to the given bean instance.
from("direct:start").bean(new ExampleBean());

// Explicit selection of bean method to be invoked.
from("direct:start").bean(new ExampleBean(), "methodName");

// Camel will create the instance of bean and cache it for you.
from("direct:start").bean(ExampleBean.class);