0

RequestMapping 是否从 Spring 3.2.1 中删除。

我正在开发一个新项目并尝试使用 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>
4

3 回答 3

3

它应该在

<dependency>
    <groupId>org.springframework</groupId>
    <artifactId>spring-web</artifactId>
    <version>${springframework-version}</version>
</dependency>

3.2.1 中有一个错误,在 3.2.2 中修复,其中spring-webmvc依赖项没有引入spring-weband spring-context,因此您必须手动声明依赖项。

它是org.springframework.web.bind.annotation.RequestMapping;

于 2013-03-08T14:16:44.027 回答
1

这是由已针对 3.2.2 修复的 3.2.1 中的问题引起的: https ://jira.springsource.org/browse/SPR-10218

也就是说,由于您使用的是@RequestMapping,因此您的 pom 应该包含对 spring-web 的依赖,而不是依赖从 spring-webmvc 到 spring-web 的传递依赖。因此,我建议在任何情况下都添加该依赖项。

于 2013-03-08T14:53:05.153 回答
0

根据 JavaDoc: http ://static.springsource.org/spring/docs/3.2.x/javadoc-api/,RequestMapping 注释似乎是 Spring 3.2.1 的一部分

也许您需要将 Spring MVC 库添加到您的项目中?

于 2013-03-08T14:19:21.420 回答