美文网首页web后台开发我爱编程
IntelliJ IDEA无法读取src下的配置文件 报错找不到

IntelliJ IDEA无法读取src下的配置文件 报错找不到

作者: 程序员学园 | 来源:发表于2018-04-09 14:47 被阅读0次

问题描述:如下在IntelliJ IDEA中中读取spring配置文件时报错,但是在eclipse中却正常,无报错

信息: 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对这些配置的文件方式很明显和eclipse是不同的。在idea中有一个 Content Roots的概念。需要为每一个folder配置相应的Content Roots。

所以需要加入如下配置即可

   <!--  intelliJ ide 需要如下配置,才能读取src目录-->
      <resources>
          <resource>
              <directory>${basedir}/src</directory>
              <includes>
                  <include>**/*.properties</include>
                  <include>**/*.xml</include>
              </includes>
          </resource>
      </resources>

完整配置如图

解决IntelliJ IDEA无法读取配置文件的问题

本文是 在线助手|在线工具箱 原创,转载请注明来自 在线助手博客频道:IntelliJ IDEA无法读取src下的配置文件 报错找不到,原文链接:http://www.it399.com/blog/web/20180409.jsp

相关文章

网友评论

    本文标题:IntelliJ IDEA无法读取src下的配置文件 报错找不到

    本文链接:https://www.haomeiwen.com/subject/kclihftx.html