File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes JMS implementation using JNDI in spring application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "JMS implementation using JNDI in spring application" Watch "JMS implementation using JNDI in spring application" New topic

JMS implementation using JNDI in spring application

saakshi jain

Joined: Sep 26, 2011
Posts: 10

I am trying to implement JMS in my spring application. I have defined the JNDI name + queue name in applicationContext.xml as follows:

<bean id="emailQueueConnectionFactory" class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true">
<property name="jndiName" value="java:comp/env/jms/<<Name of JNDI of connection factory>>" />

<bean id="emailQueueDestination" class="org.springframework.jndi.JndiObjectFactoryBean" lazy-init="true">
<property name="jndiName" value="java:comp/env/jms/<<JNDI name of queue>>" />

<bean id="emailQueueTemplate" class="org.springframework.jms.core.JmsTemplate" lazy-init="true">
<property name="connectionFactory" ref="emailQueueConnectionFactory" />
<property name="defaultDestination" ref="emailQueueDestination" />

<bean id="emailSender" class="<<Package>>.EmailSender" lazy-init="true">
<property name="jmsTemplate">
<ref bean="emailQueueTemplate" />

Now my controller makes a call to the emailSender bean using the following code:

ApplicationContext context = new ClassPathXmlApplicationContext("/applicationContext.xml");
EmailSender sender =(EmailSender)context.getBean("emailSender");

The exception I get is: Error 404: Request processing failed; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is class path resource [applicationContext.xml] cannot be opened because it does not exist

I am loading the applicationContext.xml at serevr start-up still my code is not able to locate this file.

Can anyone please help.??
Mark Spritzler

Joined: Feb 05, 2001
Posts: 17276

Basically it is saying that it is looking for that file in a particular location and it isn't located there.

Where is the file actually located?

Based on what you posted it is looking in the root of the classpath for that file.

Based on the name of the file I am assuming you are trying to use the naming convention, which includes putting the file in the WEB-INF directory. Note that that directory is not in the classpath in anyway. Typically for Spring MVC web applications, you use the ContextLoaderListener in the web.xml file to load an XmlWebApplicationContext, and that will automatically load in the WEB-INF/applicationContext.xml file and create an ApplicationContext that your Controllers loaded by the DispatcherServlet can have access to, so you can just DI the bean into your controller, via xml or @Autowired annotation.


Perfect World Programming, LLC - iOS Apps
How to Ask Questions the Smart Way FAQ
saakshi jain

Joined: Sep 26, 2011
Posts: 10
Hey.. Thanks Mark...I tried with what you suggetsed .. and it worked fine for me...
I agree. Here's the link:
subject: JMS implementation using JNDI in spring application
It's not a secret anymore!