Announcement Announcement Module
Collapse
No announcement yet.
@ContextConfiguration(locations=) for loading xml Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • @ContextConfiguration(locations=) for loading xml

    I tried migration existing test into Spring TestContext Framework, so I changed my baseTest first. Previously it looked like:

    public abstract class BaseDaoTestCase extends AbstractJpaTests {

    protected String[] getConfigLocations() {
    return new String[] {
    "classpath:/applicationContext-resources.xml",
    "classpath:/applicationContext-dao.xml",
    "classpath*:/applicationContext.xml", // for modular projects
    "classpath:**/applicationContext*.xml" // for web projects
    };
    }

    ...
    }
    Every test works fine in this case, then I changed to:

    @RunWith(SpringJUnit4ClassRunner.class)
    @ContextConfiguration(locations = {
    "classpath:/applicationContext-resources.xml",
    "classpath:/applicationContext-dao.xml",
    "classpath*:applicationContext.xml", // for modular projects
    "classpath:**/applicationContext*.xml" // for web projects
    }, inheritLocations = true)
    @TransactionConfiguration(transactionManager = "transactionManager", defaultRollback = true)
    @Transactional
    public abstract class BaseDaoTestCase extends TestCase {
    //remove getConfigLocations method
    }
    I didn't change the classpath pattern, the new BaseDaoTestCase works fine for tests in the same project. For other projects, which uses BaseDaoTestCase project jar, the resource/applicationContext.xml can't be loaded, but it worked fine for the first BaseDaoTestCase.

    Anyone has any clue?

  • #2
    can you try "classpath*:/applicationContext.xml" in stead of "classpath*:applicationContext.xml"

    Comment


    • #3
      Hi tannoy, thanks for your remind. However I've tried that even more, which just simply didn't work. Now I code the baseDaoTest with following path:

      @ContextConfiguration(locations = {
      "classpath:/applicationContext.xml",
      "classpath:/applicationContext-dao.xml",
      "classpath:/applicationContext-service.xml",
      "classpath:/applicationContext-resources.xml",
      "classpath*:/applicationContext.xml",
      "classpath:/**/applicationContext*.xml"
      }, inheritLocations = true)
      because the subclass just copy the location instead of beans defined in super-class project, so I added an empty applicationContext.xml in the super-class project (where baseDaoTest rest) as a placeholder. Then it works for sub-class project, where beans are defined in applicationContext.xml.

      The problem is kind of solved, but I still doubt wildcard (*) is working or not. Because I use "classpath:/applicationContext*.xml" to replace the first 4 lines above, it doesn't work at all.

      Comment


      • #4
        I found relevant issue on offical Jira, actually classpath*: expression in @ContextConfiguration is a bug of Spring 2.5. It's fixed in 2.5.1

        relevant Jira issue

        Comment

        Working...
        X