Hi once again, well as we comment in the last post, we pooled out the BootstrapContextFactoryBean and resourceAdapter beans and ended with something like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean
id="jencks"
class="org.jencks.JCAContainer">
<property
name="bootstrapContext"
ref="bootstrapContext" />
<property
name="resourceAdapter"
ref="activeMQResourceAdapter" />
</bean>
<bean
id="bootstrapContext"
class="org.jencks.factory.BootstrapContextFactoryBean">
<property
name="threadPoolSize"
value="25" />
</bean>
<bean
id="activeMQResourceAdapter"
class="org.activemq.ra.ActiveMQResourceAdapter">
<property
name="serverUrl"
value="tcp://10.131.5.140:61616" />
</bean>
<bean
id="holaMdp"
factory-method="addConnector"
factory-bean="jencks">
<property name="activationSpec">
<bean class="org.activemq.ra.ActiveMQActivationSpec">
<property
name="destination"
value="Hola.Queue" />
<property
name="destinationType"
value="javax.jms.Queue" />
</bean>
</property>
<property
name="bootstrapContext"
ref="bootstrapContext" />
<property
name="resourceAdapter"
ref="activeMQResourceAdapter" />
<property
name="ref"
value="holaBean" />
</bean>
<bean
id="holaBean"
class="com.telcel.activaciones.aplicacion.jms.HolaMundoBean"
singleton="true" />
</beans>
and when running, WORKS but we get a DEBUG error, should it matter that is a debug error?:
Code:
DEBUG: Ignoring BeanCreationException on FactoryBean type check
org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'holaMdp' defined in class path resource [com/telcel/activaciones/aplicacion/jms/applicationContext-mdp-jencks.xml]: Can't resolve reference to bean 'bootstrapContext' while setting property 'bootstrapContext'; nested exception is org.springframework.beans.factory.FactoryBeanNotInitializedException: Error creating bean with name 'bootstrapContext': FactoryBean returned null object: probably not fully initialized (maybe due to circular bean reference)
org.springframework.beans.factory.FactoryBeanNotInitializedException: Error creating bean with name 'bootstrapContext': FactoryBean returned null object: probably not fully initialized (maybe due to circular bean reference)
at org.springframework.beans.factory.support.AbstractBeanFactory.getObjectForSharedInstance(AbstractBeanFactory.java:800)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:191)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:176)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:105)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1012)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:823)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.getTypeForFactoryMethod(AbstractAutowireCapableBeanFactory.java:396)
at org.springframework.beans.factory.support.AbstractBeanFactory.getType(AbstractBeanFactory.java:329)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.isBeanTypeMatch(DefaultListableBeanFactory.java:249)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeanNamesForType(DefaultListableBeanFactory.java:144)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:198)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.getBeansOfType(DefaultListableBeanFactory.java:192)
at org.springframework.context.support.AbstractApplicationContext.getBeansOfType(AbstractApplicationContext.java:606)
at org.jencks.factory.WorkManagerFactoryBean.getTransactionManager(WorkManagerFactoryBean.java:114)
at org.jencks.factory.WorkManagerFactoryBean.createTransactionContextManager(WorkManagerFactoryBean.java:172)
at org.jencks.factory.WorkManagerFactoryBean.getTransactionContextManager(WorkManagerFactoryBean.java:95)
at org.jencks.factory.WorkManagerFactoryBean.createWorkManager(WorkManagerFactoryBean.java:176)
at org.jencks.factory.WorkManagerFactoryBean.afterPropertiesSet(WorkManagerFactoryBean.java:74)
at org.jencks.factory.WorkManagerFactoryBean.getWorkManager(WorkManagerFactoryBean.java:80)
at org.jencks.factory.BootstrapContextFactoryBean.getWorkManager(BootstrapContextFactoryBean.java:76)
at org.jencks.factory.BootstrapContextFactoryBean.afterPropertiesSet(BootstrapContextFactoryBean.java:63)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.invokeInitMethods(AbstractAutowireCapableBeanFactory.java:1058)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:363)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveReference(BeanDefinitionValueResolver.java:176)
at org.springframework.beans.factory.support.BeanDefinitionValueResolver.resolveValueIfNecessary(BeanDefinitionValueResolver.java:105)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.applyPropertyValues(AbstractAutowireCapableBeanFactory.java:1012)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.populateBean(AbstractAutowireCapableBeanFactory.java:823)
at org.springframework.beans.factory.support.AbstractAutowireCapableBeanFactory.createBean(AbstractAutowireCapableBeanFactory.java:345)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:226)
at org.springframework.beans.factory.support.AbstractBeanFactory.getBean(AbstractBeanFactory.java:147)
at org.springframework.beans.factory.support.DefaultListableBeanFactory.preInstantiateSingletons(DefaultListableBeanFactory.java:275)
at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:318)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:81)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:66)
at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:57)
at com.telcel.activaciones.aplicacion.jms.HolaMundoMdpApp.main(HolaMundoMdpApp.java:8)
Afterwards we took a look at the Jencks source code, and saw that we could pass the BootstrapContextFactoryBean and resourceAdapter as parameters to the JCAConnector constructor, so we ended up with a configuration like this:
Code:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE beans PUBLIC "-//SPRING//DTD BEAN//EN"
"http://www.springframework.org/dtd/spring-beans.dtd">
<beans>
<bean
id="jencks"
class="org.jencks.JCAContainer">
<property
name="bootstrapContext"
ref="bootstrapContext" />
<property
name="resourceAdapter"
ref="activeMQResourceAdapter" />
</bean>
<bean
id="bootstrapContext"
class="org.jencks.factory.BootstrapContextFactoryBean">
<property
name="threadPoolSize"
value="25" />
</bean>
<bean
id="activeMQResourceAdapter"
class="org.activemq.ra.ActiveMQResourceAdapter">
<property
name="serverUrl"
value="tcp://10.131.5.140:61616" />
</bean>
<bean
id="holaMdp"
class="org.jencks.JCAConnector">
<constructor-arg ref="bootstrapContext" />
<constructor-arg ref="activeMQResourceAdapter" />
<property name="activationSpec">
<bean class="org.activemq.ra.ActiveMQActivationSpec">
<property
name="destination"
value="Hola.Queue" />
<property
name="destinationType"
value="javax.jms.Queue" />
</bean>
</property>
<property
name="ref"
value="holaBean" />
</bean>
<bean
id="holaBean"
class="com.telcel.activaciones.aplicacion.jms.HolaMundoBean"
singleton="true" />
</beans>
And everything works and we get no error, the question here is, is it correctly configured or there was something we were missing in our first configuration in order for it to work?
If these configurations are ok, or at least one of them, the next step is to implement or not a transacted session, as we red in the http://activemq.org/Should+I+use+transactions, we are supposed to use a transacted session, since we are using Spring DataSourceTransactionMannager and if get an exception from the Service Layer injected to the Message Consumer (Message Driven POJOs) we need to re-queue the message.
Is this done in the same way with Jencks?, or is there any example we can follow, should we use a local Jms Transaction? Or any guidance?
Thanks in advance once again…