我是靠谱客的博主 搞怪蛋挞,最近开发中收集的这篇文章主要介绍解决IDEA无法读取resources文件夹,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

IDEA无法读取resources文件夹

最近在编码过程中发现在新建ClassPathXmlApplicationContext解析XML文件中,传入classpath地址可是一直在报异常FileNotFoundException

Exception in thread "main" org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [META-INF/dependency-lookup-context.xml]; nested exception is java.io.FileNotFoundException: class path resource [META-INF/dependency-lookup-context.xml] cannot be opened because it does not exist
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:345)
	at org.springframework.beans.factory.xml.XmlBeanDefinitionReader.loadBeanDefinitions(XmlBeanDefinitionReader.java:305)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:188)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:224)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:195)
	at org.springframework.beans.factory.support.AbstractBeanDefinitionReader.loadBeanDefinitions(AbstractBeanDefinitionReader.java:257)
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:128)
	at org.springframework.context.support.AbstractXmlApplicationContext.loadBeanDefinitions(AbstractXmlApplicationContext.java:94)
	at org.springframework.context.support.AbstractRefreshableApplicationContext.refreshBeanFactory(AbstractRefreshableApplicationContext.java:133)
	at org.springframework.context.support.AbstractApplicationContext.obtainFreshBeanFactory(AbstractApplicationContext.java:637)
	at org.springframework.context.support.AbstractApplicationContext.refresh(AbstractApplicationContext.java:522)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:144)
	at org.springframework.context.support.ClassPathXmlApplicationContext.<init>(ClassPathXmlApplicationContext.java:85)
	at org.geekbang.thinking.in.spring.ioc.overview.dependency.lookup.DependencyLookupDemo.main(DependencyLookupDemo.java:17)
Caused by: java.io.FileNotFoundException: class path resource [META-INF/dependency-lookup-context.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:331)
	... 13 more

跟着源码走进去发现,在类:org.springframework.beans.factory.xml.XmlBeanDefinitionReader中loadBeanDefinitions方法找出为331行报错,为encodedResource.getResource()文件无法找出,无法找到对应文件,导致报错FileNotFoundException

所以归根结底发现为文件resources文件夹无法找出

原因有两种:

1.resources文件夹未被标记,标记resources文件夹操作方式如下:

在这里插入图片描述

2.标记resources也无效,可修改pom.xml文件,在include中添加自己想要的

<build>
        <sourceDirectory>src/main/java</sourceDirectory>
        <resources>
            <resource>
                <directory>src/main/java</directory>
                <includes>
                    <include>**/*.hbm.xml</include>
                    <include>**/*.xml</include>
                </includes>
            </resource>

            <resource>
                <directory>src/main/resources</directory>
                <includes>
                    <include>**/*.xml</include>
                    <include>**/*.properties</include>
                    <include>**/*.xls</include>
                    <include>**/*.xsl</include>
                    <include>**/*.xlsx</include>
                    <include>**/*.tld</include>
                    <include>**/*.png</include>
                </includes>
            </resource>
        </resources>
    </build>

最后

以上就是搞怪蛋挞为你收集整理的解决IDEA无法读取resources文件夹的全部内容,希望文章能够帮你解决解决IDEA无法读取resources文件夹所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(49)

评论列表共有 0 条评论

立即
投稿
返回
顶部