java 包 org.springframework.web.bind.annotation 不存在,即使它是在 POM 中定义的
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/46087835/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
package org.springframework.web.bind.annotation does not exist even though it's defined in POM
提问by MassiveParty24
So I have this code
所以我有这个代码
import org.springframework.web.bind.annotation.GetMapping;
And I already have the following in my POM file
我的 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>
Yet when I built it ends up complaining package org.springframework.web.bind.annotation does not exist
然而,当我构建它时,它最终抱怨包 org.springframework.web.bind.annotation 不存在
Why? I already added spring web as a dependency. What am I doing wrong?
为什么?我已经添加了 spring web 作为依赖项。我究竟做错了什么?
回答by mirmdasif
Run the following command
运行以下命令
mvn clean install
If you are using IDE like intelliJ idea or Eclipse make sure to re import the project. Here is an answer how to refresh maven dependencies in eclipse
如果您使用像 intelliJ idea 或 Eclipse 这样的 IDE,请确保重新导入项目。这是如何在 Eclipse 中刷新 Maven 依赖项的答案
回答by Rabina
For me, removing the spring-web
dependency worked. To do this, remove the following from your pom.xml
:
对我来说,删除spring-web
依赖项有效。为此,请从您的 中删除以下内容pom.xml
:
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${spring.version}</version>
</dependency>