I use maven build in my application. I have package like:
1> src/test/java // for Test application
2> src/main/java // code
3> src/main/resource // resource files
at 1> i have written a Test file as:
public void testLoginDetails() {
new ClassPathXmlApplicationContext(
new String[] { "/com/home/app/Home-ctx.xml" });
Home-ctx is available at 2> ie src/main/java/com/home/app/Home-ctx.xml
but when i run the application I am getting following common error:
Caused by: java.io.FileNotFoundException: class path resource [com/home/app/Home-ctx.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:158)
I know this is classpath problem for xml file loading. How can I solve this?
You need to move
src/main/java/com/home/app/Home-ctx.xmlto
src/main/resources/com/home/app/Home-ctx.xmlClasspath resources need to go in a
resourcesfolder – currently you’ve got them under ajavafolder, which is for sources, not resources.If the resource is used only for testing, it should live in
src/test/resources. For production resources, they go undersrc/main/resources.References