在使用idea的时候报错:
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
查看原因可一直无法将resource中的资源文件加载到war包中。这导致程序无法 运行成功。
原因是因为我的mapper.java和mapper.xml这两种文件都存放在了同一个文件夹下。
为了能够将两者都打包到war包中,我在pom.xml文件中的build标签中添加了如下代码
<resource>
<directory>src/main/java</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
<filtering>false</filtering>
</resource>
但是这个时候突然发现无法加载resource文件了。一查才之后,如果按照上面的这种方法写的话,idea会自动忽略resource,所以还需要哈再加上一个resource内容来加载resource资源文件。
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.properties</include>
<include>**/*.xml</include>
</includes>
</resource>