Mehrdad Abdolghafari
Mehrdad Abdolghafari

Reputation: 355

Spring MVC Error : org.springframework.web.bind.annotation.RequestMapping.name()Ljava/lang/String;

what is the main reason of this error in spring mvc. I am using spring mvc 4.1.4 in my project. :

nested exception is java.lang.NoSuchMethodError: org.springframework.web.bind.annotation.RequestMapping.name()Ljava/lang/String;

Upvotes: 5

Views: 5614

Answers (2)

Zouhair Kasmi
Zouhair Kasmi

Reputation: 662

Try to delete your server and re-added again you will fix this issue.

Upvotes: 1

Alan Hay
Alan Hay

Reputation: 23226

If you go here:

https://spring.io/docs

and select 'Spring Framework' and then view the API for v3 and v4 you can see that the annotation:

org.springframework.web.bind.annotation.RequestMapping

has an attribute 'name' in v4 but not in v3.

If you then look in the WEB-INF/lib folder of your deployed app you will most likely see two different versions of the spring-web artifact, one for v3 and one for v4 and the classloader at runtime is loading the class definition from v3 rather than the one you built against (v4).

The simplest solution would be to update your POM to use the new 'Bill of Materials' feature introduced in Spring 4.

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.

Otherwise you will need to identify where the v3 JAR is being referenced and add an exclusion to prevent it being pulled in. In Eclipse, for example, you could don this by opening the POM, going to the 'dependency-hierachy' tab and typing spring-web into the filter to identify the culprit. You can then add an exclusion to the POM as detailed here:

http://maven.apache.org/guides/introduction/introduction-to-optional-and-excludes-dependencies.html

However probably easier to use the new BoM feature.

Upvotes: 3

Related Questions