2013-03-08 33 views
0

是否从Spring 3.2.1中删除了RequestMapping。是否从Spring 3.2.1中删除了RequestMapping

我工作的一个新项目,并试图使用Spring 3.2.1 ...但我的想法和Maven找不到春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从春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引起的已修复了3.2.2: https://jira.springsource.org/browse/SPR-10218

这就是说,因为你正在使用@RequestMapping,你的POM应该包括弹簧网络的依赖而不是依赖从spring-webmvc到spring-web的传递依赖。所以我建议在任何情况下添加依赖关系。

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-webspring-context,因此您必须手动声明依赖项。

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

+0

谢谢...它已经很长一段时间从我使用弹簧从无... – SJS 2013-03-08 14:18:42

+0

Np,考虑检查答案,如果它帮助你,一旦你可以。 – 2013-03-08 14:19:22

+1

有一点需要注意的是,spring-webmvc的pom.xml通常会传递spring-web。但是,由于一个bug,3.2.1中没有传入spring-web。这个问题将在3.2.2版本中解决。欲了解更多信息,请参阅JIRA https://jira.springsource.org/browse/SPR-10218 – 2013-03-08 14:50:21