aspose file tools*
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
Author

configuration location not identify in @ContextConfiguration

Harshana Dias
Ranch Hand

Joined: Jun 11, 2007
Posts: 327
I have place the configuration file for spring beans in package,
main.resources.com.springsample

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 java.io.FileNotFoundException: 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
Bartender

Joined: Mar 07, 2010
Posts: 1649
    
    7

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]
 
jQuery in Action, 2nd edition
 
subject: configuration location not identify in @ContextConfiguration