Results 1 to 3 of 3

Thread: ApplicationContext returns null in Junit Test Case

  1. #1
    Join Date
    Sep 2005
    Posts
    1

    Default ApplicationContext returns null in Junit Test Case

    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

  2. #2
    Join Date
    Feb 2005
    Posts
    217

    Default

    How does your abstract class know what spring xml files to load?

  3. #3
    Join Date
    Sep 2005
    Posts
    3

    Default

    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

Similar Threads

  1. Replies: 2
    Last Post: Oct 17th, 2005, 08:41 PM
  2. Replies: 4
    Last Post: Sep 27th, 2005, 11:31 PM
  3. Replies: 3
    Last Post: Sep 4th, 2005, 11:11 PM
  4. Strange Data Access Error
    By webifyit in forum Data
    Replies: 2
    Last Post: Dec 28th, 2004, 11:06 AM
  5. Replies: 8
    Last Post: Sep 23rd, 2004, 01:12 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •