Thursday, March 1, 2012

Spring - Multiple Application Context files from Different Projects

  • Web Application needs to use application context files bundled in separate projects.
    1. Insert the following into web.xml file



      classpath* - searches for files in the classpath.


      Project A - contains projectA-context.xml


      Project B - contains projectB-context.xml


      Project C - contains application-context.xml


      Project D - contains application-context.xml


      All 4 context files will be loaded in that order if all 4 projects are in the classpath

  • JUnit testing with multiple application context files bundled in separate projects.
    1. Add all dependent projects to the classpath when executing JUnit
    2. Include other resources in your main application context

      Project A - executed with JUnit, Spring container initiallized with projectA-context.xml

      Project B - contains projectB-context.xml

      Project C - contains application-context.xml

      Project D - contains application-context.xml

      All 4 context files will be loaded in that order if all 4 projects are in the classpath
    3. Spring application context injecting into JUnit

No comments:

Post a Comment