所以我有这段代码
import org.springframework.web.bind.annotation.GetMapping;
我的 POM 文件中已经包含以下内容
<packaging>war</packaging>
<properties>
<spring.version>4.3.0.RELEASE</spring.version>
</properties>
<dependencies>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-core</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-webmvc</artifactId>
<version>${spring.version}</version>
</dependency>
</dependencies>
然而,当我构建它时,它最终提示包 org.springframework.web.bind.annotation 不存在
为什么?我已经将 spring web 添加为依赖项。我做错了什么?
最佳答案
我有一个类似的问题,我通过进入我的 pom.xml 文件并更改 spring boot 依赖项的 artifactID 来修复它:
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter</artifactId>
</dependency>
到
<dependency>
<groupId>org.springframework.boot</groupId>
<artifactId>spring-boot-starter-web</artifactId>
</dependency>
编辑以显示解释:
我遵循的教程让我使用了错误的依赖项。如果我没记错的话,spring-boot-starter-web 依赖项包含 spring-boot-starter 的所有内容,以及制作基本 Web 应用程序所需的内容。所以我的应用程序正在寻找一些我假设 spring-boot-starter 不包含的 Web 依赖项。
关于java - 包 org.springframework.web.bind.annotation 不存在,即使它是在 POM 中定义的,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46087835/