【问题标题】:What dependency is missing for org.springframework.web.bind.annotation.RequestMapping?org.springframework.web.bind.annotation.RequestMapping 缺少什么依赖项?
【发布时间】:2012-01-15 09:38:00
【问题描述】:

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

<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>

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

【问题讨论】:

    标签: spring rest maven


    【解决方案1】:

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

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

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

    【讨论】:

    • 谢谢伙计,也为我工作。您是否知道如果我们不指定 spring 下载哪个版本?不是默认下载最新版本的吗!
    • 当我们没有指定“”标签时,它会抛出错误/异常。因此标签“”是强制性的。其次,如果您没有在此标记中指定版本,则需要指定版本标记“LATEST”/“RELEASE”(仅当您使用 Maven 2.x 时)。对于 Maven 3.x,不再支持元版本标记。始终指向最新版本的依赖项可能会在构建应用程序时产生问题。因此强烈建议使用具体的版本值。
    • 更多详情请查看StackoverflowApache Maven
    • 为我工作。现在import org.springframework.web.bind.annotation.RequestMapping; 正在工作。谢谢!
    【解决方案2】:

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

    (1) 转到您的 pom.xml

    (2) 添加这个依赖:

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


    (3) 运行你的项目

    【讨论】:

    • 谢谢,我刚刚更新了版本,因为 spring-webmvc 已经在我的 pom 中了
    【解决方案3】:

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

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

    然后,从下拉列表中,展开“spring-web”列表>选择最新版本的jar文件>点击确定。
    完成!!!

    【讨论】:

      【解决方案4】:

      我认为问题不在于依赖关系。我猜你在你的 IDE 上遇到了这个错误。然后刷新它。如果是eclipse,尝试运行Maven->Update Dependencies

      【讨论】:

        【解决方案5】:

        如需解决,请将 Spring Frame Work 更新至 3.2.0 或更高版本!

        【讨论】:

          【解决方案6】:

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

          【讨论】:

            【解决方案7】:

            有时本地 Maven 存储库中会出现一些错误。所以请关闭你的 Eclipse 并从你的本地 .m2 中删除 jar spring-webmvc 然后打开 Eclipse 并在项目上按 更新 Maven 依赖项。

            然后 Eclipse 将再次为您下载依赖项。 这就是我解决同样问题的方式。

            【讨论】:

              【解决方案8】:

              我使用的是 spring-web 版本 4.3.7

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

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

              【讨论】:

              • 我使用的是 5.1.3.RELEASE 并且遇到了同样的错误
              【解决方案9】:

              我遇到了同样的问题,但我以其他方式解决了(因为右键单击项目文件夹,只有在 pom.xml 上执行此操作时才会出现 Maven 选项卡,我才能看到 Maven 选项卡):

              所以我认为您收到该错误是因为 IDE (Eclipse) 没有从 Maven 导入依赖项。由于您使用的是 Spring 框架,并且您可能已经安装了 STS,因此右键单击项目文件夹 Spring Tools -> Update Maven Dependecies。

              我正在使用 日蚀朱诺 m2eclipse 1.3.0 Spring IDEE 3.1

              【讨论】:

                【解决方案10】:

                转到 pom.xml

                添加这个依赖:

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

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

                【讨论】:

                  【解决方案11】:

                  我几乎遇到了同样的问题,但这只是因为某些 .jar 库没有更新。

                  我无法使用@RequestMapping,因为,只需“将鼠标悬停在@RequestMapping”上并单击“修复...”,.jar 库就会被下载和安装。

                  【讨论】:

                    【解决方案12】:
                    -> Go to pom.xml
                    
                    -> Add this Dependency :
                    -> <dependency>
                        <groupId>org.springframework</groupId>
                        <artifactId>spring-webmvc</artifactId>
                        <version>4.1.6.RELEASE</version>
                    </dependency>
                    ->Wait for Rebuild or manually rebuild the project
                    ->if Maven is not auto build in your machine then manually follow below points to rebuild
                    right click on your project structure->Maven->Update Project->check "force update of snapshots/Releases"
                    

                    【讨论】:

                      【解决方案13】:
                      <dependency>
                                  <groupId>org.springframework.boot</groupId>
                                  <artifactId>spring-boot-starter-web</artifactId>
                              </dependency>
                      

                      【讨论】:

                      • OP 没有使用 Spring Boot,而只是使用了 Spring Framework。
                      【解决方案14】:

                      在您的 pom.xml 中添加以下依赖项

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

                      这用于@RestController@RequestMapping

                      【讨论】:

                        【解决方案15】:

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

                        【讨论】:

                          【解决方案16】:

                          第 1 步 - 问题出在 Eclipse IDE 第 2 步 - 右键单击​​ Maven 依赖项 -> 构建路径 -> 删除构建路径

                          为 spring-web 和 spring-webmvc 更新 pom.xml

                          第 3 步 - 更新 Maven 依赖项

                          您将看到 Spring-Web 文件将位于 maven 依赖项文件夹中。

                          【讨论】:

                            猜你喜欢
                            • 1970-01-01
                            • 2017-12-25
                            • 2015-04-18
                            • 2020-03-24
                            • 2012-07-12
                            • 1970-01-01
                            • 1970-01-01
                            • 1970-01-01
                            • 1970-01-01
                            相关资源
                            最近更新 更多