= Class Component
:doctitle: Class
:shortname: class
:artifactid: camel-bean
:description: Invoke methods of Java beans specified by class name.
:since: 2.4
:supportlevel: Stable
:tabs-sync-option:
:component-header: Only producer is supported
:core:
//Manually maintained attributes
:camel-spring-boot-name: bean

*Since Camel {since}*

*{component-header}*

The Class component binds beans to Camel message exchanges. It works
in the same way as the xref:bean-component.adoc[Bean] component, but instead of
looking up beans from a Registry, it creates the bean
based on the class name.

== URI format

----
class:className[?options]
----

Where `className` is the fully qualified class name to create and use as bean.


// component-configure options: START

// component-configure options: END

// component options: START
include::partial$component-configure-options.adoc[]
include::partial$component-endpoint-options.adoc[]
// component options: END

// endpoint options: START

// endpoint options: END

// component headers: START
include::partial$component-endpoint-headers.adoc[]
// component headers: END

== Usage

You simply use the *class* component just as the xref:bean-component.adoc[Bean]
component but by specifying the fully qualified class name instead.
For example to use the `MyFooBean` you have to do as follows:

[source,java]
-------------------------------------------------------------------------------------------------
from("direct:start")
    .to("class:org.apache.camel.component.bean.MyFooBean")
    .to("mock:result");
-------------------------------------------------------------------------------------------------

You can also specify which method to invoke on the `MyFooBean`, for
example `hello`:

[source,java]
--------------------------------------------------------------------------------------------------------------
from("direct:start")
    .to("class:org.apache.camel.component.bean.MyFooBean?method=hello")
    .to("mock:result");
--------------------------------------------------------------------------------------------------------------

== Examples

=== Setting properties on the created instance

In the endpoint uri you can specify properties to set on the created
instance, for example, if it has a `setPrefix` method:

[source,java]
---------------------------------------------------------------------------------
from("direct:start")
    .to("class:org.apache.camel.component.bean.MyPrefixBean?bean.prefix=Bye")
    .to("mock:result");
---------------------------------------------------------------------------------

And you can also use the `#` syntax to refer to properties to be looked
up in the Registry.

[source,java]
--------------------------------------------------------------------------------
from("direct:start")
    .to("class:org.apache.camel.component.bean.MyPrefixBean?bean.cool=#foo")
    .to("mock:result");
--------------------------------------------------------------------------------

Which will look up a bean from the Registry with the
id `foo` and invoke the `setCool` method on the created instance of the
`MyPrefixBean` class.

[TIP]
====
See more details on the xref:bean-component.adoc[Bean] component as the *class*
component works in much the same way.
====


include::spring-boot:partial$starter.adoc[]
