Announcement Announcement Module

Spring Modules forum decommissioned in favor of Spring Extensions

As the Spring Modules project has been replaced by the Spring Extensions ( project, this forum has been decommissioned in favour of Spring Extensions one at:

Please see the Spring Extensions home page for a complete list of current projects in Java, .NET and ActionScript. You can also propose one if you want.

Costin Leau
SpringSource - Spring Training, Consulting, and Support - "From the Source"
See more
See less
ApplicationContext returns null in Junit Test Case Page Title Module
Move Remove Collapse
Conversation Detail Module
  • Filter
  • Time
  • Show
Clear All
new posts

  • 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.

    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
    How does your abstract class know what spring xml files to load?


    • #3
      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