Thursday, July 5, 2012

Spring 3 and Mule 2 initialized by SpringXmlConfigurationBuilder

If you have a Spring 2 application using MuleESB in 2.x version, and you initialize the mule using SpringXmlConfigurationBuilder, ie. something like this:
public void startMule() throws MuleException {
    SpringXmlConfigurationBuilder builder = 
      new SpringXmlConfigurationBuilder(muleConfigResources,applicationContext);
    MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
    muleContext = muleContextFactory.createMuleContext(builder);
    runtimeConfig(muleContext); 
    muleContext.start();
}
You may notice that this simply doesn't work in Spring 3;)
After a lot of struggling I've discovered that this is because the DefaultBeanDefinitionDocumentReader interface in spring has been changed from:
protected BeanDefinitionParserDelegate createHelper(XmlReaderContext readerContext, Element root) ...
to:
protected BeanDefinitionParserDelegate createHelper(XmlReaderContext readerContext, Element root, BeanDefinitionParserDelegate parentDelegate) ...
I don't want to migrate my whole application MuleESB 3.x, what seems to have Spring 3 compatible classes, so some fixes to existing mule initialization were required here. For those interested in the same, here is the solution:
public void startMule() throws MuleException {
    Spring3XmlConfigurationBuilder builder = 
      new Spring3XmlConfigurationBuilder(muleConfigResources,applicationContext);
    MuleContextFactory muleContextFactory = new DefaultMuleContextFactory();
    muleContext = muleContextFactory.createMuleContext(builder);
    runtimeConfig(muleContext); 
    muleContext.start();
}
For this you actually need to use my classes fixing this issue - they are available to download here.

No comments:

Post a Comment