解决 java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist

前几天好好运行的web项目突然跑不起来了

报这个错误

2019-09-16 19:18:29  [ RMI TCP Connection(3)-127.0.0.1:357 ] - [ ERROR ]  Context initialization failed

org.springframework.beans.factory.BeanDefinitionStoreException: IOException parsing XML document from class path resource [applicationContext.xml]; nested exception is java.io.FileNotFoundException: class path resource [applicationContext.xml] cannot be opened because it does not exist

查了下,是找不到配置文件。

1、先考虑recourse目录下的配置文件路径是否正确。

  点击文件名可以跳转,排除这个原因。

2、检查生成的target/classes 文件下是否有配置文件。

  这是输出目录的主体,项目实际使用的配置文件就在里面。

  

 

没有找到配置文件。

 解决办法:在pom.xml中添加下面代码

<build>
    <resources>
        <resource>
            <directory>src/main/recourse</directory>
            <includes>
                <include>**/*.xml</include>
                <include>**/*.properties</include>
            </includes>
            <filtering>true</filtering>
        </resource>
    </resources>
</build>

 

<directory> 自己配置文件的路径 </directory>
<includes> 自己配置文件的种类 </includes>

 

 成功。

 

参考博客:

https://blog.csdn.net/moneyshi/article/details/53287036

https://blog.csdn.net/yyym520/article/details/80516103

 

posted @ 2019-09-16 20:30  南极石  阅读(12968)  评论(1)    收藏  举报