spring mvc 中这个错误的主要原因是什么。我在我的项目中使用 spring mvc 4.1.4。 :
nested exception is java.lang.NoSuchMethodError: org.springframework.web.bind.annotation.RequestMapping.name()Ljava/lang/String;
最佳答案
如果你去这里:
https://spring.io/docs
并选择“Spring Framework”,然后查看 v3 和 v4 的 API,您可以看到注释:
org.springframework.web.bind.annotation.RequestMapping
在 v4 中有一个属性“name”,但在 v3 中没有。
如果您随后查看已部署应用程序的 WEB-INF/lib 文件夹,您很可能会看到两种不同版本的 spring-web 工件,一种用于 v3,一种用于 v4,并且运行时的类加载器正在从 v3 加载类定义而不是您针对 (v4) 构建的那个。
最简单的解决方案是更新您的 POM 以使用 Spring 4 中引入的新“ Material list ”功能。
http://docs.spring.io/spring/docs/current/spring-framework-reference/htmlsingle/#overview-maven-bom
It is possible to accidentally mix different versions of Spring JARs when using Maven. For example, you may find that a third-party library, or another Spring project, pulls in a transitive dependency to an older release....To overcome such problems Maven supports the concept of a "bill of materials" (BOM) dependency. You can import the spring-framework-bom in your dependencyManagement section to ensure that all spring dependencies (both direct and transitive) are at the same version.
否则,您将需要确定 v3 JAR 被引用的位置并添加排除项以防止它被拉入。例如,在 Eclipse 中,您可以通过打开 POM,转到“dependency-hierachy”选项卡并键入spring-web 进入过滤器以识别罪魁祸首。然后,您可以将排除项添加到 POM,如下所述:
http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html
但是可能更容易使用新的 BoM 功能。
关于spring-mvc - Spring MVC 错误 : org. springframework.web.bind.annotation.RequestMapping.name()Ljava/lang/String;,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28437271/