Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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;
like image 654
Mehrdad Abdolghafari Avatar asked Sep 29 '22 19:09

Mehrdad Abdolghafari


2 Answers

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.

like image 53
Alan Hay Avatar answered Oct 06 '22 01:10

Alan Hay


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

like image 39
Zouhair Kasmi Avatar answered Oct 05 '22 23:10

Zouhair Kasmi