Contact Free trial Login

Configuring Java Components

Java is the default component type in Mule. Mule provides two JavaComponent implementations:

  • DefaultJavaComponent, which you configure with the `component `element

  • PooledJavaComponent, which adds pooling functionality and which you configure with the pooled-component element.

These two implementations provide the following functionality and configuration options:

  • An ObjectFactory is used to obtain the Java component implementation.

  • EntryPointResolvers can be configured to define how Mule flows should invoke the component methods when processing a message.

  • A custom LifecycleAdaptor can be configured to customize the way in which the component implementation is initialized and disposed.

  • Bindings can be configured to bind component interface methods to endpoints. These endpoints are then invoked synchronously when the method is called.

When you specify the class directly on the component or pooled-component element, the PrototypeObjectFactory is used by default, and a new instance is created for each invocation, or a new pooled component is created in the case of the PooledJavaComponent.


<component class=""/>
<pooled-component class=""/>

Alternatively, you can specify the implementation using an object factory.


    <singleton-object class=""/>
    <spring-object bean="myCustomComponentBean"/>

All other component configuration elements are configured as children of the component or pooled-component element.

Object Factories

Object factories manage both object creation in the case of a Mule instantiated instance or object look-up from another container such as Spring via a single API. The following object factories are included with Mule and can be configured using Mule’s core schema.

<prototype-object class=…​"/>


<singleton-object class=…​"/>


<spring-object bean=…​"/>


Object factories also allow you to set properties, which are injected when a new object instance is created.


    <singleton-object class="">
        <property key="myKey" value="theValue"/>
        <property key="myKey2" value="theValue2"/>

For a real-world example of using <spring-object/>, see Using Spring Beans as Flow Components.

You can easily implement additional object factories to integrate with other containers or simply to create object instances in a different way.

Note: Object factories replace ContainerContexts in previous versions of Mule.

Entry Point Resolvers

You can configure entry point resolvers that determine how your component is invoked when a message is received by the flow. See Developing Components for a more detailed description of their functionality.

To configure entry point resolvers, you can either configure an entry point resolver set or configure a single entry point resolver independently. When using an entry point resolver set, the order in which the resolvers are configured is the order of of precedence they are given in run-time.


<component class="">
<component class="">

Lifecycle Adapter Factory

You can configure your Java component to use a custom lifecycle adaptor. If you do not configure a custom implementation, the default implementation is used, which allows the optional propagation of Mule’s lifecycle to your component depending on the Mule lifecycle interfaces that are implemented.


<component class="">
    <custom-lifecycle-adapter-factory class=""/>

See Developing Components for more information about lifecycles.


Components can use bindings to call an external service during execution. The bindings used with a Java component bind a Java interface, or single interface method, to an outbound endpoint. The external service to be called should implement the same interface, and the component should encapsulate a reference to that interface, which is initialized during the bootstrap stage by the Mule configuration builder. The reference is initialized using a reflective proxy class.

Binding can be used on Java components and script components. For more information see Component Bindings.

Configuring a Pooled Java Component

A pooled Java component maintains a pool of object instances that is reused, with a single instance being used by one thread at any one time. The configuration of component pooling is independent of the object factory, allowing you to use whichever object factory you need.

You configure the pool using the nested pooling-profile element as shown below:

<pooled-component class="">
    <pooling-profile exhaustedAction="WHEN_EXHAUSTED_FAIL" initialisationPolicy="INITIALISE_ALL" maxActive="1" maxIdle="2" maxWait="3" />

For more information about pooling and reference documentation for pooling configuration options, see Tuning Performance.

Was this article helpful?

💙 Thanks for your feedback!

Edit on GitHub