• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
  • Campbell Ritchie
  • Ron McLeod
  • Tim Cooke
  • Liutauras Vilda
  • Jeanne Boyarsky
  • Paul Clapham
  • Rob Spoor
  • Junilu Lacar
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Piet Souris
  • Carey Brown

configuration location not identify in @ContextConfiguration

Ranch Hand
Posts: 352
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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 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");

Posts: 1682
Android Mac OS X IntelliJ IDE Spring Linux
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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

    Bookmark Topic Watch Topic
  • New Topic