JBOSS AS 6 Startup: ConnectionFactory Not Bound

So here I was, minding my own business migrating my Spring based application from JBoss 5.1.0.GA to JBoss 6.1. On an ordinary day, JBoss 5 will have been fine for me (otherwise move straight to 7), but RHQ doesn’t sit nicely with JBoss 5, and I didn’t want to risk deploying a major application to a customer on the freshly cut JBoss 7.

I got a very nasty surprise when after creating my datasource definitions, configuring all my JMS queues, deploying my native libraries to their appropriate locations and starting up my server, I get the ff exception.

 javax.naming.NameNotFoundException: ConnectionFactory not bound

And yet when I looked at the JNDIView in the JMX console under http://localhost:8080/jmx-console, the ConnectionFactory was bound to the global namespace i.e. /ConnectionFactory and the “java” namespace i.e. java:/ConnectionFactory. Looking at the console, I then noticed the ff statements after the log statements showing my application had failed deployment.

16:36:38,045 INFO  [HornetQServerImpl] trying to deploy queue jms.queue.UpdateQueue

Hmm, it seems that the HornetQ inside JBoss 6 starts up the ConnectionFactory and queues/topics after everything else has started up, and not before. I still don’t know why JBoss designed it that way, seeing as some applications may need to immediately connect to JMS resources at startup.

A little “googling” about and I found how to make the JMS resources bootstrap before any web application is deployed. Simply look for the following file under your JBoss 6 installation. Replace my path with your appropriate locations.

K:\dev\ jboss-6.1.0.Final\server\default\deploy\jbossweb.sar\META-INF\jboss-beans.xml

Add the ff declarations as dependencies to the “WebServer” MBean, and you should be fine.

 <depends>org.hornetq:module=JMS,name=”NettyConnectionFactory”,type=ConnectionFactory</depends>

<depends>org.hornetq:module=JMS,name=”InVMConnectionFactory”,type=ConnectionFactory</depends>

<depends>org.hornetq:module=JMS,name=”NettyThroughputConnectionFactory”,type=ConnectionFactory</depends>

Now whip up your JBoss again, and you’ll notice that the queues/topics are deployed before any web application. You’re in business now.