sivaram
sivaram

Reputation: 29

why application context cannot be loaded?

can any body explain why should i getting the following error message "Failed to load ApplicationContext" while testing my test cases

 mvn test

Upvotes: 0

Views: 1557

Answers (3)

FrVaBe
FrVaBe

Reputation: 49341

Check your @ContextConfiguration. Quote from the Spring documentation:

A plain or relative path — for example "context.xml" — will be treated as a classpath resource that is relative to the package in which the test class is defined. A path starting with a slash is treated as an absolute classpath location, for example "/org/example/config.xml". A path which represents a resource URL (i.e., a path prefixed with classpath:, file:, http:, etc.) will be used as is.

So I suppose you have to use "/applicationContext.xml" instead of "/src/test/resources/applicationContext.xml" as the file will be placed at the root level in your classpath.

Upvotes: 1

Manuel Quinones
Manuel Quinones

Reputation: 4246

Since I can't see your configuration you could just change your Test to use the following class level annotations. This should help find the application context as long as it is in the classpath.

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration({ "classpath:applicationContext.xml" })

Upvotes: 0

sp00m
sp00m

Reputation: 48817

If your using the Spring framework, you can specify the location of your applicationContext.xml file using the @ContextConfiguration annotation:

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration(locations = { "/path/to/your/applicationContext.xml" })
public class MyTest {

}

Upvotes: 2

Related Questions