页面运行后出现如下错误:
HTTP Status 500 - 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
在控制台有如下错误:
log4j:WARN No appenders could be found for logger (org.springframework.core.env.StandardEnvironment).
log4j:WARN Please initialize the log4j system properly.
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
出现这个错误的原因是maven编译时没有将xml文件和properties配置文件放到target中的classes目录下。
解决方法如下:
在pom.xml文件中添加如下代码
<build>
...
<resources>
<!-- 不编译resources下的配置文件 -->
<resource>
<directory>src/main/resources</directory>
<includes>
<include>**/*.xml</include>
<include>**/*.properties</include>
</includes>
<filtering>true</filtering>
</resource>
</resources>
...
</build>
再次运行Tomcat,就成功了。