我有一个应用程序,其中有一个带有 @RequestMapping
注释的 Spring @Controller
。
使用 Spring(核心和 webmvc)4.1.0.RELEASE 或更高版本启动应用程序服务器时出现异常。
java.lang.NoSuchMethodError: org.springframework.web.bind.annotation.RequestMapping.name()Ljava/lang/String;
at method RequestMappingHandlerMapping.createRequestMappingInfo(RequestMapping annotation, RequestCondition<?> customCondition)
使用Eclipse检查进行调试,方法变量annotation
不包含name
属性,并且在操作annotation.name()
处失败。所有其他属性值都是正确的(它们具有在使用 @RequestMapping
注释的 Controller 方法中定义的值)。
我正在使用 Tomcat 7 和 Maven 2.3。
mvn dependency:tree
不显示 4.1.0.RELEASE 以外的其他 Spring 版本。
使用 Spring 4.0.7.RELEASE 或更低版本时不会出现该错误。
有人知道吗?
最佳答案
似乎是类路径问题。正在加载旧版本的 RequestMapping。
关于java - Spring MVC。加载上下文时无法识别 RequestMapping 注释名称属性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26405691/