We Are Going To Discuss About java.io.FileNotFoundException: class path resource cannot be opened because it does not exist. So lets Start this Java Article.
java.io.FileNotFoundException: class path resource cannot be opened because it does not exist
- java.io.FileNotFoundException: class path resource cannot be opened because it does not exist
What you put directly under
src/main/java
is in the default package, at the root of the classpath. It's the same for resources put undersrc/main/resources
: they end up at the root of the classpath. - java.io.FileNotFoundException: class path resource cannot be opened because it does not exist
What you put directly under
src/main/java
is in the default package, at the root of the classpath. It's the same for resources put undersrc/main/resources
: they end up at the root of the classpath.
Solution 1
What you put directly under src/main/java
is in the default package, at the root of the classpath. It’s the same for resources put under src/main/resources
: they end up at the root of the classpath.
So the path of the resource is app-context.xml
, not main/resources/app-context.xml
.
Original Author JB Nizet Of This Content
Solution 2
We can also try this solution
ApplicationContext ctx = new ClassPathXmlApplicationContext("classpath*:app-context.xml");
in this the spring automatically finds the class in the class path itself
Original Author Saurabh Verma Of This Content
Solution 3
Try this:
ApplicationContext context = new ClassPathXmlApplicationContext("app-context.xml");
Original Author Mouad EL Fakir Of This Content
Solution 4
The file location/path has to relative to your classpath locations. If resources directory is in your classpath you just need “app-context.xml” as file location.
Original Author Gomsy Of This Content
Conclusion
So This is all About This Tutorial. Hope This Tutorial Helped You. Thank You.