Struts 2
  1. Struts 2
  2. WW-3443

StrutsSpringTestCase does not support multiple spring xml configuration files

    Details

    • Type: Bug Bug
    • Status: Closed
    • Priority: Major Major
    • Resolution: Fixed
    • Affects Version/s: 2.1.8.1
    • Fix Version/s: 2.2.3
    • Component/s: None
    • Labels:
      None

      Description

      Spring has a great concept that you can load the xml configuration and define beans with the same name multiple times and the convention is that the lasr definition takes precedence. This is great for testing as we usually load the normal (production) application context xml then load a test application context xml which just overides the beans that need to be changed for that test.

      Currently the StrutsSpringTestCase does not support defining multiple application context xml files for a test. I rewrote the class so that the method protected String getContextLocations() is now protected String[] getContextLocations(). We can now load multiple application context xml files.

        Activity

        Hide
        Ty Connell added a comment -

        I was able to overcome this by overriding the protected method setupBeforeInitDispatcher like so:

        @Override
        protected void setupBeforeInitDispatcher() throws Exception {
        String[] contextLocations = new String[]

        { "classpath:applicationContext-security.xml", "classpath:applicationContext.xml", "classpath:junitApplicationContext.xml" }

        ;

        GenericXmlContextLoader xmlContextLoader = new GenericXmlContextLoader();
        applicationContext = xmlContextLoader.loadContext(contextLocations);
        servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext);
        }

        Show
        Ty Connell added a comment - I was able to overcome this by overriding the protected method setupBeforeInitDispatcher like so: @Override protected void setupBeforeInitDispatcher() throws Exception { String[] contextLocations = new String[] { "classpath:applicationContext-security.xml", "classpath:applicationContext.xml", "classpath:junitApplicationContext.xml" } ; GenericXmlContextLoader xmlContextLoader = new GenericXmlContextLoader(); applicationContext = xmlContextLoader.loadContext(contextLocations); servletContext.setAttribute(WebApplicationContext.ROOT_WEB_APPLICATION_CONTEXT_ATTRIBUTE, applicationContext); }
        Hide
        Lukasz Lenart added a comment -

        Done, now you can override getContextLocations() method to specify as many context locations you want

        protected String[] getContextLocations() {
        return new String[]

        {DEFAULT_CONTEXT_LOCATION}

        ;
        }

        Show
        Lukasz Lenart added a comment - Done, now you can override getContextLocations() method to specify as many context locations you want protected String[] getContextLocations() { return new String[] {DEFAULT_CONTEXT_LOCATION} ; }

          People

          • Assignee:
            Lukasz Lenart
            Reporter:
            Paul Grove
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development