Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

configuration location not identify in @ContextConfiguration

 
Harshana Dias
Ranch Hand
Posts: 333
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 1682
7
Android IntelliJ IDE Linux Mac OS X Spring
  • Mark post as helpful
  • send pies
  • 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


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic