java.io.FileNotFoundException: class path resource cannot be opened because it does not exist

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

  1. 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 under src/main/resources: they end up at the root of the classpath.

  2. 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 under src/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.

Also Read,

Siddharth

I am an Information Technology Engineer. I have Completed my MCA And I have 4 Year Plus Experience, I am a web developer with knowledge of multiple back-end platforms Like PHP, Node.js, Python and frontend JavaScript frameworks Like Angular, React, and Vue.

Leave a Comment