spring入门第一坑,解决报错class path resource [spring.xml] cannot be opened because it does not exist……
•
Jave
下面这几行代码大家应该都很熟悉,就是 Spring 的 “Hello World”。
![spring入门第一坑,解决报错class path resource [spring.xml] cannot be opened because it does not exist......](/img/1a/7d52ec94b13c46b8b331e31b0d987019.png)
那么我们在运行这个 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入门第一坑,解决报错class path resource [spring.xml] cannot be opened because it does not exist......](/img/18/b7f41e8e26a0446984426adaeddb9e52.png)
大概意思就是没有找到 spring.xml 这个配置文件,仔细看 spring.xml 是在 resource 目录下,貌似是没啥问题
![spring入门第一坑,解决报错class path resource [spring.xml] cannot be opened because it does not exist......](/img/74/296c27e1f18b4f3ebed3ae9cc536bead.png)
再展开看下 target 目录发现了问题所在,这是因为在 Idea 中,编译器只会把 src/main/java 也就是源代码目录下的 .java 文件编译成 .class 文件然后放到 target 目录中,其他的默认不会。
![spring入门第一坑,解决报错class path resource [spring.xml] cannot be opened because it does not exist......](/img/ab/d40c5f14c4f24a2c89297d5d678bc697.png)
这里我们只需要将 spring.xml 文件复制到 target/classes/ 下即可解决
![spring入门第一坑,解决报错class path resource [spring.xml] cannot be opened because it does not exist......](/img/e6/ed584045148b4d67b5220f268ca555d2.png)
然后再运行试一下,OK啦。
![spring入门第一坑,解决报错class path resource [spring.xml] cannot be opened because it does not exist......](/img/03/b8f572eaf43f4d01b41a2e0a755cb434.png)
本文来自网络,不代表协通编程立场,如若转载,请注明出处:https://net2asp.com/8ca5a0de4e.html
