I have got it working, well almost. Need a little more help.
I have setup a web project (where the spring beans are) and an EJB project where the MDB resides. I created the applicationContext.xml and the beanRefContext.xml in the source directory of the web project.
The beanRefContext.xml simply points to the applicationContext file like this,
Code:
<beans>
<bean id="MyApp" class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg>
<list><value>applicationContext.xml</value></list>
</constructor-arg>
</bean>
</beans>
And my MDB looks like this,
Code:
public void setMessageDrivenContext(MessageDrivenContext messageDrivenContext) throws EJBException {
super.setMessageDrivenContext(messageDrivenContext);
setBeanFactoryLocator(ContextSingletonBeanFactoryLocator.getInstance());
setBeanFactoryLocatorKey("MyApp");
}
public void onMessage(Message arg0) {
TextMessage msg=(TextMessage)arg0;
try {
System.err.println(" Receive "+msg.getText());
BeanFactory f=getBeanFactory();
GreetingServiceImpl b=(GreetingServiceImpl) f.getBean("GreetingServiceImpl");
System.err.println("Message from Spring Bean="+b.getMessage());
} catch (JMSException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
When I send a message to the queue, I get this exception:
Code:
<MessageDrivenBean threw an Exception in onMessage(). The exception was:
java.lang.reflect.InvocationTargetException.
I have a a feeling my project structure is not quite right. Where should the XML files (context & ref) reside, in the EJB project or in the spring (web) project? Any other thoughts?
Thanks