Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

JMS implementation using JNDI in spring application

 
saakshi jain
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 17278
6
IntelliJ IDE Mac Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
saakshi jain
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hey.. Thanks Mark...I tried with what you suggetsed .. and it worked fine for me...
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic