問(wèn)題描述:如下在IntelliJ IDEA中中讀取spring配置文件時(shí)報(bào)錯(cuò),但是在eclipse中卻正常电抚,無(wú)報(bào)錯(cuò)
信息: Loading XML bean definitions from class path resource [bean.xml]
Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [bean.xml]; nested exception is java.io.FileNotFoundException: class path resource [bean.xml] cannot be opened because it does not exist
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:343)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:303)
at com.spring.ioc.Application.main(Application.java:25)
Caused by: java.io.FileNotFoundException: class path resource [bean.xml] cannot be opened because it does not exist
at org.springframework.core.io.ClassPathResource.getInputStream(ClassPathResource.java:180)
at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:329)
... 2 more
idea對(duì)這些配置的文件方式很明顯和eclipse是不同的列另。在idea中有一個(gè) Content Roots的概念贡必。需要為每一個(gè)folder配置相應(yīng)的Content Roots武学。
所以需要加入如下配置即可
<!-- intelliJ ide 需要如下配置,才能讀取src目錄-->
<resources>
<resource>
<directory>${basedir}/src</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>
</resources>
完整配置如圖
解決IntelliJ IDEA無(wú)法讀取配置文件的問(wèn)題
本文是 在線助手|在線工具箱 原創(chuàng)栈源,轉(zhuǎn)載請(qǐng)注明來(lái)自 在線助手博客頻道:IntelliJ IDEA無(wú)法讀取src下的配置文件 報(bào)錯(cuò)找不到,原文鏈接:http://www.it399.com/blog/web/20180409.jsp