为什么我的Eclipse/Maven/Spring项目看不到注解@RequestMapping?
Why can't my Eclipse/Maven/Spring project see the annotation @RequestMapping?
我在 Eclipse 中有一个用于 Web 应用程序的简单 Maven 项目。
我在 pom.xml 文件中添加了以下依赖项 ...
<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>
我创建了一个简单的网络控制器class ...
import org.springframework.stereotype.Controller;
@Controller
public class WebController {
@RequestMapping(value="/method0")
@ResponseBody
public String method0(){
return "method0";
}
}
...项目可以很好地找到@Controller 注解,但@RequestMapping 和@ResponseBody 注解出现红色错误。
我清理了所有东西,重建了所有东西,没有运气。
我检查了项目中的Java Build Path,路径中添加了"Maven Dependencies",它包括以下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
此外,我的理解是 org.springframework.web.bind.annotation.RequestMapping
注释应该在 spring-webmvc-5.0.4.RELEASE.jar 中,但我解压缩了 JAR 文件但我没有在那里看到它。
我做错了什么?
我找到了解决办法。我从我的 .m2 存储库中删除了 spring-web 和 spring-webmvc jar,并进行了 maven clean 和 maven 安装,它 re-downloaded JAR 文件现在 JAR 文件中包含正确的文件.可能是上次下载依赖的时候出错了,很奇怪。不过现在有工作所以我很好
我在 Eclipse 中有一个用于 Web 应用程序的简单 Maven 项目。
我在 pom.xml 文件中添加了以下依赖项 ...
<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>
我创建了一个简单的网络控制器class ...
import org.springframework.stereotype.Controller;
@Controller
public class WebController {
@RequestMapping(value="/method0")
@ResponseBody
public String method0(){
return "method0";
}
}
...项目可以很好地找到@Controller 注解,但@RequestMapping 和@ResponseBody 注解出现红色错误。
我清理了所有东西,重建了所有东西,没有运气。
我检查了项目中的Java Build Path,路径中添加了"Maven Dependencies",它包括以下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
此外,我的理解是 org.springframework.web.bind.annotation.RequestMapping
注释应该在 spring-webmvc-5.0.4.RELEASE.jar 中,但我解压缩了 JAR 文件但我没有在那里看到它。
我做错了什么?
我找到了解决办法。我从我的 .m2 存储库中删除了 spring-web 和 spring-webmvc jar,并进行了 maven clean 和 maven 安装,它 re-downloaded JAR 文件现在 JAR 文件中包含正确的文件.可能是上次下载依赖的时候出错了,很奇怪。不过现在有工作所以我很好