spring org.springframework.web.bind.annotation.RequestMapping 缺少什么依赖项?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/8422720/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-08 04:47:53  来源:igfitidea点击:

What dependency is missing for org.springframework.web.bind.annotation.RequestMapping?

springrestmaven

提问by Rolando

What dependency am I missing? I am currently using:

我缺少什么依赖项?我目前正在使用:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>

The error Im getting is: The import org.springframework.web.bind cannot be resolved

我得到的错误是:无法解析导入 org.springframework.web.bind

回答by MAC

I had the same problem. After spending hours, I came across the solution that I already added dependency for "spring-webmvc" but missed for "spring-web". So just add the below dependency to resolve this issue. If you already have, just update both to the latest version. It will work for sure.

我有同样的问题。花了几个小时后,我发现我已经为“ spring-webmvc”添加了依赖但错过了“ spring-web”的解决方案。因此,只需添加以下依赖项即可解决此问题。如果您已经拥有,只需将两者都更新到最新版本即可。它肯定会起作用。

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.1.6.RELEASE</version>
</dependency>

You could update the version to "5.1.2" or latest. I used V4.1.6 therefore the build was failing, because this is an old version (one might face compatibility issues).

您可以将版本更新为“5.1.2”或最新版本。我使用的是 V4.1.6,因此构建失败,因为这是一个旧版本(可能会遇到兼容性问题)。

回答by Danish Sofwan

This solution WORKS , I had the same issue and after hours I came up to this:

这个解决方案有效,我遇到了同样的问题,几小时后我想到了这个:

(1) Go to your pom.xml

(2) Add this Dependency :

(1) 转到您的 pom.xml

(2) 添加此依赖项:

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>


(3) Run your Project


(3) 运行你的项目

回答by Alejandro Diaz

I don't think the problem is the dependencies. I guess you are getting that error on your IDE. Then just refresh it. If it's eclipse, try running Maven->Update Dependencies

我不认为问题是依赖关系。我猜您在 IDE 上遇到了该错误。然后只需刷新它。如果是 Eclipse,请尝试运行 Maven->Update Dependencies

回答by AVA

To resolve, Update Spring Frame Work to 3.2.0 or above!

解决,更新Spring Frame Work到3.2.0或以上!

回答by Anuj Panwar

I think You are using Spring 3.0.5 and you need to use Spring 4.0.* This will resolve your problem. org.springframework.web.bind.annotation.RequestMapping is not available in Spring-web earlier then Spring-web 4.0.*

我认为您使用的是 Spring 3.0.5,您需要使用 Spring 4.0。* 这将解决您的问题。org.springframework.web.bind.annotation.RequestMapping 在 Spring-web 中不可用,然后 Spring-web 4.0.*

回答by Linus Gwabha

I was using spring-web version 4.3.7

我使用的是 spring-web 版本 4.3.7

Changing it to a working 4.1.7 immediately solved it.

将其更改为有效的 4.1.7 立即解决了它。

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.1.7.RELEASE</version>
    </dependency>

回答by Xelian

Sometimes there is some error in the local Maven repo. So please close your eclipse and delete the jar spring-webmvc from your local .m2 then open Eclipse and on the project press Update Maven Dependencies.

有时本地 Maven 存储库中存在一些错误。因此,请关闭您的 Eclipse 并从您的本地 .m2 中删除 jar spring-webmvc,然后打开 Eclipse 并在项目上按 Update Maven Dependencies。

Then Eclipse will download the dependency again for you. That how I fixed the same problem.

然后 Eclipse 将再次为您下载依赖项。那是我如何解决同样的问题。

回答by Daniel Tremblay

the problem's actually caused by dependency. I spent whole the day to solve this prblm. Firstly, right click on project > Maven > add dependency

问题实际上是由依赖性引起的。我花了一整天来解决这个问题。首先,右键单击项目> Maven > 添加依赖项

enter image description here

在此处输入图片说明

In "EnterGroupId, ArtifactId, or sha1...." box, type "org.springframework".

在“EnterGroupId、ArtifactId 或 sha1....”框中,输入“org.springframework”。

Then, from droped down list, expand "spring-web" list > Choose the newest version of jar file > Click OK.enter image description here
Done!!!

然后,从下拉列表中,展开“spring-web”列表 > 选择最新版本的 jar 文件 > 单击“确定”。完毕!!!在此处输入图片说明

回答by Frank Song

Thanks above all of you contributions! however for my case I finally realized that my dependency above "spring-web" was destroyed on my .m2/repository/org/springframework/spring-web, I just deleted the folder and update Maven again. it got fixed.

感谢以上所有贡献!但是对于我的情况,我终于意识到我对“spring-web”的依赖在我的 .m2/repository/org/springframework/spring-web 上被破坏了,我只是删除了该文件夹并再次更新 Maven。它得到了修复。

回答by a3rxander

Go to pom.xml

转到 pom.xml

Add this Dependency :

添加此依赖项:

   <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>

using command prompt, find your folder: - mvn clean

使用命令提示符,找到您的文件夹:- mvn clean