spring-mvc - Spring MVC 错误 : org. springframework.web.bind.annotation.RequestMapping.name()Ljava/lang/String;

标签 spring-mvc spring-security

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/

相关文章:

spring-security - 如何在 Java 类中使用 Spring 的 "user-by-username-query"子句?

java - 避免在 RESTful Web 服务中加载整个对象图

java - 除了 localhost,如何配置与 Spring 集成的嵌入式 Tomcat 以监听 IP 地址请求?

java - 在 Spring Boot 中创建路径

java - 有没有更有效的方法将 mp4 文件发送给用户

java - 在 Controller 上使用 Spring PreAuthorize 后使用 AspectJ 进行审核

java - 如何在Spring TaskExecutor中分配任务名称并检查它是否仍然存在?

java - Spring4.0.3中AuthenticationException.getAuthentication()的替换是什么

java - 在 Spring 中保护 REST 资源的更好方法?

java - 尝试重现 spring security OAuth2Login 示例时不断收到错误