CameronBraid
Aug 16th, 2004, 11:28 AM
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 :
<bean id="activeMQ" class="ActiveMQ">
<property name="location"><value>classpath:activeMQ.xml</value></property>
</bean>
class ActiveMQ implements InitializingBean, ApplicationContextAware {
...
public void afterPropertiesSet() throws Exception {
// validation of properties here
BeanDefinitionRegistry registry = null;
if (parentContext instanceof ConfigurableApplicationContext) {
// merge the bean befinitions into the parent's registry
BeanFactory beanFactory = ((ConfigurableApplicationContext)parentContext).ge tBeanFactory();
if (beanFactory instanceof BeanDefinitionRegistry) {
registry = (BeanDefinitionRegistry)beanFactory;
new ActiveMQBeanDefinitionReader(registry).loadBeanDef initions(location);
}
}
// handle (registry == null) case
}
}
This code causes an exception
java.util.ConcurrentModificationException
at java.util.LinkedList$ListItr.checkForComodificatio n(LinkedList.java:552)
at java.util.LinkedList$ListItr.next(LinkedList.java: 488)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:198)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:279)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:81)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:66)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:57)
at Main.main(Main.java:13)
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 ?
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 :
<bean id="activeMQ" class="ActiveMQ">
<property name="location"><value>classpath:activeMQ.xml</value></property>
</bean>
class ActiveMQ implements InitializingBean, ApplicationContextAware {
...
public void afterPropertiesSet() throws Exception {
// validation of properties here
BeanDefinitionRegistry registry = null;
if (parentContext instanceof ConfigurableApplicationContext) {
// merge the bean befinitions into the parent's registry
BeanFactory beanFactory = ((ConfigurableApplicationContext)parentContext).ge tBeanFactory();
if (beanFactory instanceof BeanDefinitionRegistry) {
registry = (BeanDefinitionRegistry)beanFactory;
new ActiveMQBeanDefinitionReader(registry).loadBeanDef initions(location);
}
}
// handle (registry == null) case
}
}
This code causes an exception
java.util.ConcurrentModificationException
at java.util.LinkedList$ListItr.checkForComodificatio n(LinkedList.java:552)
at java.util.LinkedList$ListItr.next(LinkedList.java: 488)
at org.springframework.beans.factory.support.DefaultL istableBeanFactory.preInstantiateSingletons(Defaul tListableBeanFactory.java:198)
at org.springframework.context.support.AbstractApplic ationContext.refresh(AbstractApplicationContext.ja va:279)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:81)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:66)
at org.springframework.context.support.ClassPathXmlAp plicationContext.<init>(ClassPathXmlApplicationContext.java:57)
at Main.main(Main.java:13)
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 ?