下面這幾行代碼大家應(yīng)該都很熟悉,就是 Spring 的 "Hello World"。
?那么我們?cè)谶\(yùn)行這個(gè) main方法可能會(huì)遇到【報(bào)錯(cuò)】: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 這個(gè)配置文件,仔細(xì)看 spring.xml 是在 resource 目錄下,貌似是沒啥問題
再展開看下 target 目錄發(fā)現(xiàn)了問題所在,這是因?yàn)樵?Idea 中,編譯器只會(huì)把 src/main/java 也就是源代碼目錄下的 .java 文件編譯成 .class 文件然后放到 target 目錄中,其他的默認(rèn)不會(huì)。
?這里我們只需要將 spring.xml 文件復(fù)制到 target/classes/ 下即可解決
然后再運(yùn)行試一下,OK啦。文章來源:http://www.zghlxwxcb.cn/news/detail-503992.html
文章來源地址http://www.zghlxwxcb.cn/news/detail-503992.html
到了這里,關(guān)于spring入門第一坑,解決報(bào)錯(cuò)class path resource [spring.xml] cannot be opened because it does not exist......的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!