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

前端 未结 4 1384
一向
一向 2020-12-13 10:25

I am trying to set the configuration location for my Project but I keep getting the following error:

java.io.FileNotFoundException: class path resourc

相关标签:
4条回答
  • 2020-12-13 10:51

    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.

    0 讨论(0)
  • 2020-12-13 10:53

    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.

    0 讨论(0)
  • 2020-12-13 11:00

    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

    0 讨论(0)
  • 2020-12-13 11:12

    Try this:

    ApplicationContext context = new ClassPathXmlApplicationContext("app-context.xml");
    
    0 讨论(0)
提交回复
热议问题