MuleContext muleContext = new DefaultMuleContextFactory().createMuleContext();
ConfigurationBuilder builder = new SpringXmlConfigurationBuilder("spring-beans.xml, mule-config.xml");
builder.configure(muleContext);
muleContext.start();
Spring Application Contexts
This page describes the options available for controlling how Mule creates and manages Spring application contexts for your application.
Single Application Context
By default, Mule will combine all resource files into a single ApplicationContext
, whether they are "pure" Spring files or Mule configuration files. For example, the following code will create a single application context consisting of the objects in spring-beans.xml
plus the objects in mule-config.xml
:
Single Application Context |
---|
Or, in a more abbreviated form:
MuleContext muleContext = new DefaultMuleContextFactory().createMuleContext(
new SpringXmlConfigurationBuilder("spring-beans.xml, mule-config.xml"));
muleContext.start();
Multiple Application Contexts
You can instruct Mule to create a separate application context for each Mule configuration file. The following code will create two application contexts, one for each configuration resource:
Multiple Application Contexts |
---|
|
Using an Existing Application Context
If you already have an application context, you can instruct Mule to use it as follows:
Using an Existing Application Context |
---|
|
Using an Existing Application Context as Parent
You can designate an existing application context as a parent context for Mule, so that the Mule configuration can refer to and/or override beans in the application context:
Using an Existing Application Context as Parent |
---|
|
The MuleXmlBuilderContextListener
class checks to see if an application context (WebApplicationContext
) has already been created by Spring, and if there is one, Mule uses it as the parent automatically.