Announcement Announcement Module
Collapse
No announcement yet.
Help with integration of custom beans xml format Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Help with integration of custom beans xml format

    I am trying to help the ActiveMQ people with integration of their configuration file format into a spring application context.

    Currently they use a custom XmlBeanDefinitionReader that uses XSLT to transform their xml file format into a normal spring format.

    This works fine when someone loads their configuration by instantiating a ActiveMQBeanFactory instance (which uses ActiveMQBeanDefinitionReader internally)

    The issue that I am facing is the integration of this process with a normal applicationContext.xml file.

    I want to merge the bean definitions from a transfomed ativeMQ.xml file into an existing application context. How can this be done ?

    I attempted to do it with :

    Code:
        <bean id="activeMQ" class="ActiveMQ">
            <property name="location"><value>classpath&#58;activeMQ.xml</value></property>
        </bean>
    Code:
    class ActiveMQ implements InitializingBean, ApplicationContextAware &#123;
        ...
        public void afterPropertiesSet&#40;&#41; throws Exception &#123;
            
            // validation of properties here
            
            BeanDefinitionRegistry registry = null;
            
            if &#40;parentContext instanceof ConfigurableApplicationContext&#41; &#123;
                // merge the bean befinitions into the parent's registry
               BeanFactory beanFactory = &#40;&#40;ConfigurableApplicationContext&#41;parentContext&#41;.getBeanFactory&#40;&#41;;
                if &#40;beanFactory instanceof BeanDefinitionRegistry&#41; &#123;
                    registry = &#40;BeanDefinitionRegistry&#41;beanFactory;
                    new ActiveMQBeanDefinitionReader&#40;registry&#41;.loadBeanDefinitions&#40;location&#41;;
                &#125;
            &#125;
            
            // handle &#40;registry == null&#41; case
            
        &#125;
    
    &#125;

    This code causes an exception
    Code:
    java.util.ConcurrentModificationException
    	at java.util.LinkedList$ListItr.checkForComodification&#40;LinkedList.java&#58;552&#41;
    	at java.util.LinkedList$ListItr.next&#40;LinkedList.java&#58;488&#41;
    	at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons&#40;DefaultListableBeanFactory.java&#58;198&#41;
    	at org.springframework.context.support.AbstractApplicationContext.refresh&#40;AbstractApplicationContext.java&#58;279&#41;
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>&#40;ClassPathXmlApplicationContext.java&#58;81&#41;
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>&#40;ClassPathXmlApplicationContext.java&#58;66&#41;
    	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>&#40;ClassPathXmlApplicationContext.java&#58;57&#41;
    	at Main.main&#40;Main.java&#58;13&#41;

    I have also considered making a child context, and load the activeMQ definitions into there, but the problem is that some beans defined in activeMQ.xml may be needed in the parent context.

    Any thoughts / ideas / suggestions ?

  • #2
    I think we've solved this

    After a bit of chat on the ActiveMQ irc we've figured this one out.

    The ActiveConnectionFactory is gonna have a property of the broker, then we'll use a BrokerFactoryBean which can take a Spring Resource as a constructor / property to allow Spring to configure the broker on a connection factory - yet keeping the broker XML config file separate to the normal Spring XML configuration.

    This allows us to use a custom XMLBeanFactory for the ActiveMQ broker - such as to take advantage of our customized ActiveMQ config file format (to save typing, using elements like broker, connection, transport etc).

    So I think we've got this one sorted now

    Comment

    Working...
    X