*
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
Author

JMS implementation using JNDI in spring application

saakshi jain
Greenhorn

Joined: Sep 26, 2011
Posts: 10
Hi,

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>

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

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

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

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 java.io.FileNotFoundException: 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
ranger
Sheriff

Joined: Feb 05, 2001
Posts: 17249
    
    6

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.

Mark


Perfect World Programming, LLC - Two Laptop Bag - Tube Organizer
How to Ask Questions the Smart Way FAQ
saakshi jain
Greenhorn

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: http://aspose.com/file-tools
 
subject: JMS implementation using JNDI in spring application
 
Similar Threads
Spring : Tomcat datasource via JNDI in my Spring configuration Problem
No unique bean of type [javax.persistence.EntityManagerFactory] is defined: but found 0
IBM MQ vs JMS - Spring Implementation
Spring+JMS+OC4J
Create session automatically