Results 1 to 4 of 4

Thread: @ContextConfiguration(locations=) for loading xml

  1. #1
    Join Date
    Jan 2008
    Posts
    17

    Default @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. #2

    Default

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

  3. #3
    Join Date
    Jan 2008
    Posts
    17

    Default

    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.

  4. #4
    Join Date
    Jan 2008
    Posts
    17

    Default

    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

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •