DefaultMessageListenerContainer troubles in Websphere
By: Michel.Schudel, 3 February 2010Using the Spring DefaultMessageListenerContainer makes it easy for you to connect to a jms resource like a Queue so you can pick up messages from that queue.
Using this container in Websphere (6.0, 6.1, 7) some problems occur when you want to do the following:
- You use a resource environment reference for your destination, specified in the web.xml, for the Destination.
- You use the property
destinationNameon theDefaultMessageListenerContainerin combination with aJndiDestinationResolverto look up your resource environment reference like this:java:comp/env/jms/(your destination)
problem
When you try to start the application, you will get an exception like this: javax.naming.NameNotFoundException: Name "comp/env/jms/(your destination)" not found in context "java:"., although you are sure that your resource environment reference is defined correctly.
cause
The cause of this problem lies in the fact that the lookup occurs in a Thread started by the DefaultMessageListenerContainer, which is unmanaged by Websphere. This thread will not have the jndi queue bindings in its InitialContext.
solution
You can either:
- Specifiy the jndi object beforehand with a
JndiObjectFactoryBean, or a, and then
<jee:jndi-lookup id="myqueue" jndi-name="java:comp/env/jms/(your destination)"/>
setting thedestinationproperty of theDefaultMessageListenerContainerto the refmyqueue, so no actual lookup occurs within the thread of the listener itself. -
Delegate the listener’s thread to Websphere with the help of the Spring class
WorkManagerTaskExecutor. You can then set the propertytaskExecutoron the message listener container to reference this class. See the IBM article here for details on how to do this.

4 February 2010 om 9:10 pm
Thanks. I’m gonna create some Spring Message Driven POJO’s soon and thy need to run in WAS 7.
I’m bookmarking this post as a reference!
4 February 2010 om 9:14 pm
Or, you could just go one floor up for 10 minutes…
4 February 2010 om 9:37 pm
I’ll probably do that too.