Uploaded image for project: 'Spring Framework'
  1. Spring Framework
  2. SPR-9863

Support WebApplicationContext hierarchies in the TestContext Framework


    • Type: New Feature
    • Status: Resolved
    • Priority: Major
    • Resolution: Complete
    • Affects Version/s: 2.5 final
    • Fix Version/s: 3.2.2
    • Component/s: Test, Web
    • Labels:
    • Last commented by a User:



      This issue picks up where SPR-5243 left off. Specifically this issue focuses on adding support for WebApplicationContext hierarchies within single test classes as well as within test class hierarchies.

      Consequently, this issue is heavily dependent on the completion of both SPR-5243 and SPR-5613.


      • Ensure that common WAC hierarchies can be configured in integration tests (e.g., root and dispatcher WACs in a parent-child relationship).


      1. Ensure that hierarchies of WACs can be configured using @ContextHierarchy (see SPR-5613)
      2. Ensure that the type of the root WAC can differ from that of its parent (e.g., a standard ApplicationContext loaded for an EAR)
      3. Set a loaded context as the ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE in the MockServletContext when context hierarchies are used:
        • if an ApplicationContext has no parent and the context is a WAC, set the context as the root WAC
        • if an ApplicationContext has a parent that is not a WAC and the context itself is a WAC, set the context as the root WAC

      Pseudocode Examples

      Root WAC & Dispatcher WAC
      @WebAppConfiguration // path defaults to "file:src/main/webapp"
          @ContextConfiguration(name="root", classes = WebAppConfig.class),
          @ContextConfiguration(name="dispatcher", locations="/spring/dispatcher-config.xml")
      public class ControllerIntegrationTests {}

      Class & Context Hierarchies
      public abstract class AbstractWebTests {}
      public class SoapWebServiceTests extends AbstractWebTests {}
      public class RestWebServiceTests extends AbstractWebTests {}

      Class & Context Hierarchies with Merged and Overridden Configuration

      In ExtendedControllerIntegrationTests the configuration for the root WAC will be overridden, and the configuration for the dispatcher WAC will be merged.

      @WebAppConfiguration // defaults to "file:src/main/webapp"
          @ContextConfiguration(name="root", classes = WebAppConfig.class),
          @ContextConfiguration(name="dispatcher", locations="/spring/user-config.xml")
      public class ControllerIntegrationTests {}
          @ContextConfiguration(name="root", locations="/spring/root2.xml", inheritLocations=false),
          @ContextConfiguration(name="dispatcher", locations="/spring/orders-config.xml"),
      public class ExtendedControllerIntegrationTests extends ControllerIntegrationTests {}


          Issue Links



              • Assignee:
                sbrannen Sam Brannen
                sbrannen Sam Brannen
                Last updater:
                Sam Brannen
              • Votes:
                3 Vote for this issue
                7 Start watching this issue


                • Created:
                  Days since last comment:
                  5 years, 37 weeks, 5 days ago