[英]JMS implementation using JNDI in spring application
I am trying to implement JMS in my spring application. 我正在尝试在我的spring应用程序中实现JMS。 I have defined the JNDI name + queue name in applicationContext.xml as follows:
我在applicationContext.xml中定义了JNDI名称+队列名称,如下所示:
<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`enter code here`.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: 现在,我的控制器使用以下代码调用emailSender bean:
ApplicationContext context = new ClassPathXmlApplicationContext("/applicationContext.xml");
EmailSender sender =(EmailSender)context.getBean("emailSender");
The exception I get is: Error 404: Request processing failed; 我得到的异常是:错误404:请求处理失败; nested exception is org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml];
嵌套的异常是org.springframework.beans.factory.BeanDefinitionStoreException:IOException从类路径资源[applicationContext.xml]解析XML文档。 nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist
嵌套的异常为java.io.FileNotFoundException:类路径资源[applicationContext.xml]无法打开,因为它不存在
I am loading the applicationContext.xml at serevr start-up still my code is not able to locate this file. 我在serevr启动时正在加载applicationContext.xml,但我的代码仍无法找到该文件。
Can anyone please help.?? 谁能帮忙吗?
确保您的applicationContext.xml文件位于类路径中,然后添加类路径前缀,您可以尝试这样的操作
ApplicationContext context = new ClassPathXmlApplicationContext("classpath*:applicationContext.xml");
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.