首页 文章

为什么Maven在没有Servlet依赖的情况下成功编译?

提问于
浏览
0

我正在写一个spring-mvc应用程序(和学习spring-mvc) . 我没有向pom.xml添加servlet依赖项 . 当我运行 mvn compilemvn package 时,它会成功完成 . Isn 't it suppose to throw exception like '找不到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:compile [INFO] org.codehaus.jackson:jackson-core-asl:jar:1.9.12:compile [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:compile [INFO] org.springframework:spring-jdbc:jar:3.2.1.RELEASE:compile [INFO] org.springframework:spring-tx:jar :3.2.1.RELEASE:编译[INFO] org.springframework:spring-web :jar:3.2.1.RELEASE:编译[INFO] org.springframework:spring-webmvc:jar:3.2.1.RELEASE:compile [INFO] postgresql:postgresql:jar:9.2-1002.jdbc4:compile

3 回答

  • 0

    不完全相关:仍然在学习spring-mvc时我建议只保留pom中所需的依赖关系,它会告诉你哪个jar有哪些类 .

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

  • 1

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

  • 0

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

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

    mvn dependency:tree
    

相关问题