File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Spring and the fly likes configuration location not identify in @ContextConfiguration Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Spring
Bookmark "configuration location not identify in @ContextConfiguration" Watch "configuration location not identify in @ContextConfiguration" New topic

configuration location not identify in @ContextConfiguration

Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 331
I have place the configuration file for spring beans in package,

But when i try to load it with below, the file couldn't identified. It always take the path where the current test class reside (different package from where xml file reside)

Caused by: org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [test/com/springsample//main/resources/com/springsample/springsample-introductions.xml]; nested exception is class path resource [test/com/springsample//main/resources/com/springsample/springsample-introductions.xml] cannot be opened because it does not exist

But when i try without annotation like below, it recognized the file successfully,
ApplicationContext context =
new ClassPathXmlApplicationContext("\\main\\resources\\com\\springsample\\springsample-introductions.xml");

Bill Gorder

Joined: Mar 07, 2010
Posts: 1682

Best practice says test cases should have their own configuration. This way you can define only the beans needed by the test case and you keep production configuration separate from test configuration. You should put these in src/test/resources not src/main/resources/

I assume this is for a test case as that is what @ContextConfiguration is used for.

That said my next suggesting is stop using \ and start using / that way you don't have to escape them.

Start on the root of the classpath and try

or alternatively

[How To Ask Questions][Read before you PM me]
I agree. Here's the link:
subject: configuration location not identify in @ContextConfiguration
It's not a secret anymore!