环境介绍:
jdk1.7
tomcat 8.0
eclipse 4.4.1
maven 3.2.3
部署一个简单应用工程,访问页面后发现,报如下错误:
错误原因分析:
web.xml内容如下:
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/javaee
http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
version="3.0">
<display-name>platform</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
<welcome-file>index.html</welcome-file>
</welcome-file-list>
</web-app>
访问index.jsp报错,但访问index.html是正常的。
在部署后的工程中查找发现如下jar包:
servlet-api-2.3.jar
初步判定是该包与tomcat的容器jar包冲突引起的。尝试直接在部署工程中删除。
结果:
index.jsp页面访问正常。
问题:
该包是如何部署在工程中的?
问题分析:
分析pom.xml文件中的每一个包,发现是spring-hibernate3会传递依赖servlet-api-2.3.jar包;
解决方法:
加入以下红色部分:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-hibernate3</artifactId>
<version>2.0.8</version>
<type>jar</type>
<exclusions>
<exclusion>
<groupId>javax.servlet</groupId>
<artifactId>servlet-api</artifactId>
</exclusion>
</exclusions>
</dependency>
验证:
重新部署运行后,一切访问正常。