6

我继续学习 maven 并试图理解为什么我得到这个错误包“org.springframework.web.servlet 不存在”,而 org.springframework.web 依赖项已经在 pom.xml 中定义。

 <groupId>com.home.springtraining</groupId
<artifactId>SpringTrainingTemplate</artifactId>
  <version>1.0-SNAPSHOT</version>
  <packaging>jar</packaging>
  <name>SpringTrainingTemplate</name>
  <url>http://maven.apache.org</url>
  <properties>
<spring.version>3.1.1.RELEASE</spring.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
  </properties>
  <dependencies>
<dependency>
<groupId>org.springframework</groupId>
    <artifactId>spring-core</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-context</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-beans</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-jdbc</artifactId>
    <version>${spring.version}</version>
</dependency>
<dependency>    
    <groupId>commons-logging</groupId>  
    <artifactId>commons-logging</artifactId>  
    <version>1.1.1</version>  
</dependency>
<dependency>    
    <groupId>commons-io</groupId>  
    <artifactId>commons-io</artifactId>  
    <version>2.3</version>  
</dependency>
<dependency>
    <groupId>javax.servlet</groupId>
    <artifactId>servlet-api</artifactId>
    <version>2.4</version>
</dependency>
<dependency>
  <groupId>junit</groupId>
  <artifactId>junit</artifactId>
  <version>3.8.1</version>
  <scope>test</scope>
</dependency>

你能告诉我为什么会出现这个错误吗?

4

2 回答 2

9

org.springframework.web.servlet是 Spring MVC 的一部分,它位于org.springframework:spring-webmvc工件中:

<dependency> 
    <groupId>org.springframework</groupId> 
    <artifactId>spring-webmvc</artifactId> 
    <version>${spring.version}</version> 
</dependency> 

org.springframework:spring-web包含在 Web 应用程序中使用 Spring 的常用功能,它不依赖于 Spring MVC。

于 2012-09-26T14:18:29.620 回答
2

将此依赖项添加到您的 pom.xml

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>3.1.1.RELEASE</version>
</dependency>
于 2012-09-26T14:19:06.177 回答