Why can't my Eclipse/Maven/Spring project see the annotation @RequestMapping?

Robert Hume Source

I have a simple maven project in Eclipse for a web app.

I added the following dependencies to the pom.xml file ...

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

I created a simple web controller class ...

import org.springframework.stereotype.Controller;

@Controller
public class WebController {

    @RequestMapping(value="/method0")
    @ResponseBody
    public String method0(){
        return "method0";
    }

}

... the project can find the @Controller annotation fine, but there's red errors on the @RequestMapping and @ResponseBody annotations.

I cleaned everything, rebuilt everything, no luck.

I checked the Java Build Path in the project, and the "Maven Dependencies" is added to the path, and it includes the following JARs ...

spring-context-5.0.4.RELEASE.jar
spring-aop-5.0.4.RELEASE.jar
spring-beans-5.0.4.RELEASE.jar
spring-core-5.0.4.RELEASE.jar
spring jcl-5.0.4.RELEASE.jar
spring-expression-5.0.4.RELEASE.jar
spring-webmvc-5.0.4.RELEASE.jar
spring-web-5.0.4.RELEASE.jar

Also, my understanding is the org.springframework.web.bind.annotation.RequestMapping annotation is supposed to be in the spring-webmvc-5.0.4.RELEASE.jar, but I unzipped the JAR file and I don't see it in there.

What am I doing wrong?

springeclipsemavenspring-mvcspring-web

Answers

answered 7 months ago Robert Hume #1

I found a solution. I deleted the spring-web and spring-webmvc jars from my .m2 repository and did a maven clean and maven install, it re-downloaded the JAR files and now the JAR file has the correct files in it. Perhaps something went wrong the last time it download the dependencies, very weird. But working now so I'm good.

comments powered by Disqus