spring入门第一坑,解决报错class path resource [spring.xml] cannot be opened because it does not exist......

下面这几行代码大家应该都很熟悉,就是 Spring 的 "Hello World"。

 那么我们在运行这个 main方法可能会遇到【报错】:Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [spring.xml]; nested exception is java.io.FileNotFoundException: class path resource [spring.xml] cannot be opened because it does not exist......就像这样:

大概意思就是没有找到 spring.xml 这个配置文件,仔细看 spring.xml 是在 resource 目录下,貌似是没啥问题

再展开看下 target 目录发现了问题所在,这是因为在 Idea 中,编译器只会把 src/main/java 也就是源代码目录下的 .java 文件编译成 .class 文件然后放到 target 目录中,其他的默认不会。

 这里我们只需要将 spring.xml 文件复制到 target/classes/ 下即可解决

扫描二维码关注公众号,回复: 15597357 查看本文章

然后再运行试一下,OK啦。

猜你喜欢

转载自blog.csdn.net/qq_42490860/article/details/129534982