PDA

View Full Version : ApplicationContext returns null in Junit Test Case


penku
Sep 16th, 2005, 02:21 PM
Hi All,
I am new to spring framework , Just wanted to know if there is any plug in required for testing DAO component (uses both Spring & Hibernate ) in Junit Test class.

For example spring provides Struts ContextLoaderPlugIn from where it gets the application context.
org.springframework.web.struts.ContextLoaderPlugIn


Basically I have written a abstract class which extends org.springframework.test.AbstractSpringContextTest s class and then I am calling my Junit Test class by extending the base class.

In Junit test class construter , am trying to access the bean
dao= (DAO) applicationContext.getBean("dao");

Thanks in advance

cwilkes
Sep 17th, 2005, 09:17 AM
How does your abstract class know what spring xml files to load?

vinu
Sep 17th, 2005, 02:28 PM
Try this
XmlBeanFactory bf = new XmlBeanFactory(new ClassPathResource("myFile.xml", getClass()));

Replace 'myfile.xml' with your bean definition xml, and make availbale in the classpath