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

问题描述:如下在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。

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

   
      <resources>
          <resource>
              <directory>${basedir}/srcdirectory>
              <includes>
                  <include>**/*.propertiesinclude>
                  <include>**/*.xmlinclude>
              includes>
          resource>
      resources>

完整配置如图

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

你可能感兴趣的:(java后台)