40

What dependency am I missing? I am currently using:

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>
<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>3.0.5.RELEASE</version>
</dependency>

The error Im getting is: The import org.springframework.web.bind cannot be resolved

Rolando
  • 58,640
  • 98
  • 266
  • 407

16 Answers16

70

I had the same problem. After spending hours, I came across the solution that I already added dependency for "spring-webmvc" but missed for "spring-web". So just add the below dependency to resolve this issue. If you already have, just update both to the latest version. It will work for sure.

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>4.1.6.RELEASE</version>
</dependency>

You could update the version to "5.1.2" or latest. I used V4.1.6 therefore the build was failing, because this is an old version (one might face compatibility issues).

Ram
  • 3,887
  • 4
  • 27
  • 49
  • Thanks mate, worked for me too. Do you have any idea that if we don't specify the version which one does spring download? Doesn't it download the latest version by default ! – varunkr Jun 20 '17 at 11:58
  • 1
    It throws error(s)/exception(s) when we don't specify the "" tag. Hence the tag "" is mandatory. Second if you don't specify the version inside this tag, you would need to specify the version markers "LATEST"/ "RELEASE" (Only when you are working with Maven 2.x). For Maven 3.x, the meta version markers are not supported anymore. As always pointing to the latest version of dependencies may create problem while building the app. Therefore It is highly recommended to use concrete values of versions. – Ram Jun 21 '17 at 08:39
  • 1
    For more details check [Stackoverflow](https://stackoverflow.com/questions/30571/how-do-i-tell-maven-to-use-the-latest-version-of-a-dependency) and [Apache Maven](https://cwiki.apache.org/confluence/display/MAVEN/Maven+3.x+Compatibility+Notes#Maven3.xCompatibilityNotes-PluginMetaversionResolution) – Ram Jun 21 '17 at 08:50
  • Worked for me. Now the `import org.springframework.web.bind.annotation.RequestMapping;` is actually working. Thanks! – Sylhare Sep 08 '17 at 02:35
31

This solution WORKS , I had the same issue and after hours I came up to this:

(1) Go to your pom.xml

(2) Add this Dependency :

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>


(3) Run your Project

Danish Sofwan
  • 333
  • 3
  • 9
10

the problem's actually caused by dependency. I spent whole the day to solve this prblm. Firstly, right click on project > Maven > add dependency

enter image description here

In "EnterGroupId, ArtifactId, or sha1...." box, type "org.springframework".

Then, from droped down list, expand "spring-web" list > Choose the newest version of jar file > Click OK.enter image description here
Done!!!

Daniel Tremblay
  • 146
  • 1
  • 6
6

I don't think the problem is the dependencies. I guess you are getting that error on your IDE. Then just refresh it. If it's eclipse, try running Maven->Update Dependencies

Alejandro Diaz
  • 431
  • 2
  • 9
4

To resolve, Update Spring Frame Work to 3.2.0 or above!

AVA
  • 2,474
  • 2
  • 26
  • 41
2

I think You are using Spring 3.0.5 and you need to use Spring 4.0.* This will resolve your problem. org.springframework.web.bind.annotation.RequestMapping is not available in Spring-web earlier then Spring-web 4.0.*

Anuj Panwar
  • 113
  • 7
2

Sometimes there is some error in the local Maven repo. So please close your eclipse and delete the jar spring-webmvc from your local .m2 then open Eclipse and on the project press Update Maven Dependencies.

Then Eclipse will download the dependency again for you. That how I fixed the same problem.

Xelian
  • 16,680
  • 25
  • 99
  • 152
2

I was using spring-web version 4.3.7

Changing it to a working 4.1.7 immediately solved it.

    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>4.1.7.RELEASE</version>
    </dependency>
2
<dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
jyotinadda
  • 51
  • 3
0

I had the same problem but I solved in other way (becouse at right click on project folder no Maven tab apears only if I do that on pom.xml I can see a Maven tab):

So I tink that you get that error because the IDE (Eclipse) didn`t import the dependecies from Maven. Since you are using Spring framework and you probably have STS allready installed right-click on project folder Spring Tools -> Update Maven Dependecies.

I`m using Eclipse JUNO m2eclipse 1.3.0 Spring IDEE 3.1

Cassian
  • 3,648
  • 1
  • 29
  • 40
0

Go to pom.xml

Add this Dependency :

   <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-webmvc</artifactId>
        <version>4.1.6.RELEASE</version>
    </dependency>

using command prompt, find your folder: - mvn clean

a3rxander
  • 868
  • 2
  • 10
  • 17
0

I had almost the same problem but it was just because some .jar library wasn't updated.

I couldn't use @RequestMapping cause that, just "mouse over @RequestMapping" and click on "Fix ..." and the .jar library will be downloading and installing.

Ruben Es
  • 19
  • 2
0
-> Go to pom.xml

-> Add this Dependency :
-> <dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-webmvc</artifactId>
    <version>4.1.6.RELEASE</version>
</dependency>
->Wait for Rebuild or manually rebuild the project
->if Maven is not auto build in your machine then manually follow below points to rebuild
right click on your project structure->Maven->Update Project->check "force update of snapshots/Releases"
0

Add this below dependency in your pom.xml

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
</dependency>

This is used for @RestController, @RequestMapping

Mark Rotteveel
  • 100,966
  • 191
  • 140
  • 197
rahulnikhare
  • 1,362
  • 1
  • 18
  • 25
0

Thanks above all of you contributions! however for my case I finally realized that my dependency above "spring-web" was destroyed on my .m2/repository/org/springframework/spring-web, I just deleted the folder and update Maven again. it got fixed.

0

Step 1 - The problem is with Eclipse IDE Step 2 - Right Click Maven Dependencies -> Build Path -> Remove Build Path

Update pom.xml for spring-web and spring-webmvc

Step 3 - Update Maven Dependencies

You will see the Spring-Web files will be in the maven dependencies folder.