java已从Spring 3.2.1中删除
从Spring 3.2.1中删除了RequestMapping
我正在做一个新项目,并尝试使用Spring3.2.1。。。但是我的想法和Maven在春天找不到。。下面是我的控制器:
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>
# 1 楼答案
它应该在里面
3.2.1 fixed in 3.2.2中有一个bug,
spring-webmvc
依赖项没有引入spring-web
和spring-context
,因此您必须手动声明依赖项是
org.springframework.web.bind.annotation.RequestMapping;
# 2 楼答案
这是由3.2.1中的问题引起的,该问题已在3.2.2中修复: https://jira.springsource.org/browse/SPR-10218
也就是说,因为您使用的是@RequestMapping,所以pom应该包含对SpringWeb的依赖,而不是依赖于从SpringWebMVC到SpringWeb的可传递依赖。因此,我建议在任何情况下都添加这种依赖关系
# 3 楼答案
根据JavaDoc:http://static.springsource.org/spring/docs/3.2.x/javadoc-api/,RequestMapping注释似乎是Spring3.2.1的一部分
也许您需要将SpringMVC库添加到您的项目中