从Spring 3.2.1中删除了RequestMapping。
我正在开发一个新项目并试图使用Spring 3.2.1 ...但我的IDEA和Maven无法在Spring中找到RequestMapping ..下面是我的控制器:
package org.sample.jquery.controller;
import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.servlet.ModelAndView;
import static org.apache.log4j.Logger.getLogger;
@Controller
@RequestMapping("/request")
public class RequestController {
private static final Logger LOGGER = getLogger(RequestController.class);
@RequestMapping(method = RequestMethod.GET)
public ModelAndView displayRequestPage() {
return new ModelAndView("input");
}
}
这是我的pom.xml ....看起来RequestMapping已从Spring 3.2.1中删除
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
<modelVersion>4.0.0</modelVersion>
<groupId>jQueryExamples</groupId>
<artifactId>jQueryExamples</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>jQueryExamples Maven Webapp</name>
<url>http://maven.apache.org</url>
<developers>
<developer>
...
</developer>
</developers>
<properties>
<java-version>1.7</java-version>
<springframework-version>3.2.1.RELEASE</springframework-version>
<org.slf4j-version>1.6.6</org.slf4j-version>
</properties>
<dependencies>
<!-- the following is for spring -->
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-context</artifactId>
<version>${springframework-version}</version>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-webmvc</artifactId>
<version>${springframework-version}</version>
<exclusions>
<exclusion>
<groupId>commons-logging</groupId>
<artifactId>commons-logging</artifactId>
</exclusion>
</exclusions>
</dependency>
<!-- This is for logging with log4j -->
<dependency>
<groupId>log4j</groupId>
<artifactId>log4j</artifactId>
<version>1.2.17</version>
</dependency>
<!-- this is for junit testing -->
<dependency>
<groupId>junit</groupId>
<artifactId>junit</artifactId>
<version>3.8.1</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<finalName>jQueryExamples</finalName>
</build>
</project>
答案 0 :(得分:3)
它应该在
中<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-web</artifactId>
<version>${springframework-version}</version>
</dependency>
3.2.1 fixed in 3.2.2中存在一个错误,其中spring-webmvc
依赖关系未引入spring-web
和spring-context
,因此您必须手动声明依赖性。
这是org.springframework.web.bind.annotation.RequestMapping;
答案 1 :(得分:1)
这是由3.2.1中针对3.2.2修复的问题引起的: https://jira.springsource.org/browse/SPR-10218
那就是说,既然你正在使用@RequestMapping,你的pom应该包含对spring-web的依赖,而不是依赖spring-webmvc到spring-web的传递依赖。因此,我建议在任何情况下都添加该依赖项。
答案 2 :(得分:0)
根据JavaDoc,似乎RequestMapping注释是Spring 3.2.1的一部分:http://static.springsource.org/spring/docs/3.2.x/javadoc-api/
也许你需要将Spring MVC库添加到你的项目中?