0

我正在编写一个 spring-mvc 应用程序(并学习 spring-mvc)。我没有向 pom.xml 添加 servlet 依赖项。当我运行mvn compileormvn package时,它成功完成。是不是应该抛出像“找不到 javax.servlet.http.HttpServlet”这样的异常?它是如何编译的?

mvn 依赖项:列表:

以下文件已解决:[INFO]
aopalliance:aopalliance:jar:1.0:compile [INFO]
commons-dbcp:commons-dbcp:jar:1.4:compile [INFO]
commons-pool:commons-pool:jar:1.5。 4: 编译 [INFO]
log4j:log4j:jar:1.2.17: 编译 [INFO]
org.codehaus.jackson:jackson-core-asl:jar:1.9.12: 编译 [INFO]
org.codehaus.jackson:jackson- mapper-asl:jar:1.9.12:compile [INFO]
org.slf4j:jcl-over-slf4j:jar:1.7.2:compile [INFO]
org.slf4j:slf4j-api:jar:1.7.2:compile [ INFO]
org.slf4j:slf4j-log4j12:jar:1.7.2:compile [INFO]
org.springframework:spring-aop:jar:3.2.1.RELEASE:compile [INFO]
org.springframework:spring-beans:jar: 3.2.1.RELEASE:编译[INFO]
org.springframework:spring-context:jar:3.2.1.RELEASE:compile [INFO]
org.springframework:spring-core:jar:3.2.1.RELEASE:compile [INFO]
org.springframework:spring-expression:jar: 3.2.1.RELEASE:编译[INFO] org.springframework:spring-jdbc:jar:3.2.1.RELEASE:编译[INFO]
org.springframework:spring-tx:jar:3.2.1.RELEASE:编译[INFO]
org.springframework:spring-web:jar:3.2.1.RELEASE:compile [INFO]
org.springframework:spring-webmvc:jar:3.2.1.RELEASE:compile [INFO]
postgresql:postgresql:jar:9.2-1002。 jdbc4:编译

4

3 回答 3

1

因为,Servlet Api 是 spring-webmvc 的传递依赖。默认情况下,Maven 包含所有传递依赖项。

使用以下命令列出依赖项及其传递依赖项

mvn dependency:tree
于 2013-03-18T03:24:58.687 回答
0

因为 servlet API 是 的依赖项org.springframework:spring-webmvc,因此是项目的传递依赖项。

于 2013-03-17T15:59:28.450 回答
0

不完全实现:仍然在您学习 spring-mvc 时,我建议仅在 pom 中保留所需的依赖项,这将告诉您哪个 jar 具有哪组类。

还为 spring 特定的包配置日志记录和调试,这极大地支持了理解流程或可能出现的问题。当我从春天开始时,它对我帮助很大。快乐学习:)

于 2013-03-18T04:54:13.520 回答