SpringGWT-无法添加RESTfulWebService-请求映射异常

SpringGWT-无法添加RESTfulWebService-请求映射异常,spring,rest,spring-mvc,Spring,Rest,Spring Mvc,我启动了一个gwt spring 3项目,该项目的想法是spring roo。然后我将roo从项目中移除,并实现了spring安全性,一切都按预期进行 但是我在向我的项目中添加restful控制器时遇到了一个问题。基本上这应该很容易,但是,因为我使用的是GWT,所以可能与一些配置有关 org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.web.servlet.mvc.method.ann

我启动了一个gwt spring 3项目,该项目的想法是spring roo。然后我将roo从项目中移除,并实现了spring安全性,一切都按预期进行

但是我在向我的项目中添加restful控制器时遇到了一个问题。基本上这应该很容易,但是,因为我使用的是GWT,所以可能与一些配置有关

org.springframework.beans.factory.BeanCreationException:创建名为“org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerMapping#0”的bean时出错:bean初始化失败;嵌套的异常是java.lang.NoSuchMethodError:org.springframework.web.bind.annotation.RequestMapping.consumes()[Ljava/lang/String

我原以为这意味着我缺少某种依赖性,但我检查了一下,我在研究的所有示例项目中使用了所有可能的和必需的spring依赖性,所以我假设这是另一回事

下面是我的restful控制器

@RequestMapping("/api")
@Controller
public class TestControler {

   @RequestMapping("/test")
   @ResponseBody
   public String getAll() {
      return "aba";
   }
我的
web.xml

    <context-param>
        <param-name>defaultHtmlEscape</param-name>
        <param-value>true</param-value>
    </context-param>

    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>classpath*:META-INF/spring/applicationContext*.xml 
        </param-value>
    </context-param>

    <filter>
        <filter-name>CharacterEncodingFilter</filter-name>
        <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
        <init-param>
            <param-name>encoding</param-name>
            <param-value>UTF-8</param-value>
        </init-param>
        <init-param>
            <param-name>forceEncoding</param-name>
            <param-value>true</param-value>
        </init-param>
    </filter>

    <filter>
        <filter-name>HttpMethodFilter</filter-name>
        <filter-class>org.springframework.web.filter.HiddenHttpMethodFilter</filter-class>
    </filter>

    <filter>
        <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
        <filter-class>org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter</filter-class>
    </filter>    

    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <filter>
        <filter-name>springSecurityFilterChain</filter-name>
        <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
    </filter>
    <filter-mapping>
        <filter-name>springSecurityFilterChain</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>    

    <filter-mapping>
        <filter-name>CharacterEncodingFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>HttpMethodFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>

    <filter-mapping>
        <filter-name>Spring OpenEntityManagerInViewFilter</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>    

    <!-- Handles Spring requests -->
    <servlet>
        <servlet-name>myapp</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>WEB-INF/spring/webmvc-config.xml</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

    <servlet>
        <servlet-name>requestFactory</servlet-name>
        <servlet-class>com.myapp.CustomRequestFactoryServlet</servlet-class>
    </servlet>       

    <servlet-mapping>
        <servlet-name>myapp</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>    

    <servlet-mapping>
        <servlet-name>requestFactory</servlet-name>
        <url-pattern>/gwtRequest</url-pattern>
    </servlet-mapping>
    <session-config>
        <session-timeout>10</session-timeout>
    </session-config>

默认HTMLescape
真的
上下文配置位置
classpath*:META-INF/spring/applicationContext*.xml
字符编码滤波器
org.springframework.web.filter.CharacterEncodingFilter
编码
UTF-8
强制编码
真的
HttpMethodFilter
org.springframework.web.filter.hiddenhttmpmethodfilter
Spring OpenEntityManager视图过滤器
org.springframework.orm.jpa.support.OpenEntityManagerInViewFilter
org.springframework.web.context.ContextLoaderListener
springSecurityFilterChain
org.springframework.web.filter.DelegatingFilterProxy
springSecurityFilterChain
/*
字符编码滤波器
/*
HttpMethodFilter
/*
Spring OpenEntityManager视图过滤器
/*
myapp
org.springframework.web.servlet.DispatcherServlet
上下文配置位置
WEB-INF/spring/webmvc-config.xml
1.
请求工厂
com.myapp.CustomRequestFactoryServlet
myapp
/
请求工厂
/gwtRequest
10
我的servlet spring mvc配置

<context:component-scan base-package="br.ufsc.inf.citymobile"
    use-default-filters="false">
    <context:include-filter expression="org.springframework.stereotype.Controller"
        type="annotation" />
</context:component-scan>

<mvc:annotation-driven />

<mvc:resources location="/, classpath:/META-INF/web-resources/"
    mapping="/resources/**" />

<mvc:default-servlet-handler />

<mvc:interceptors>
    <bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor" />
    <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor"
        p:paramName="lang" />
</mvc:interceptors>

<mvc:view-controller path="/" view-name="index" />
<mvc:view-controller path="/uncaughtException" />
<mvc:view-controller path="/resourceNotFound" />
<mvc:view-controller path="/dataAccessFailure" />

<bean       class="org.springframework.context.support.ReloadableResourceBundleMessageSource"
    id="messageSource" p:basenames="WEB-INF/i18n/messages,WEB-INF/i18n/application"
    p:fallbackToSystemLocale="false" />

<bean class="org.springframework.web.servlet.i18n.CookieLocaleResolver"
    id="localeResolver" p:cookieName="locale" />

<bean
    class="org.springframework.ui.context.support.ResourceBundleThemeSource"
    id="themeSource" />

<bean class="org.springframework.web.servlet.theme.CookieThemeResolver"
    id="themeResolver" p:cookieName="theme" p:defaultThemeName="standard" />

<bean       class="org.springframework.web.servlet.handler.SimpleMappingExceptionResolver"
    p:defaultErrorView="uncaughtException">
    <property name="exceptionMappings">
        <props>
            <prop key=".DataAccessException">dataAccessFailure</prop>
            <prop key=".NoSuchRequestHandlingMethodException">resourceNotFound</prop>
            <prop key=".TypeMismatchException">resourceNotFound</prop>
            <prop key=".MissingServletRequestParameterException">resourceNotFound</prop>
        </props>
    </property>
</bean>

<bean
    class="org.springframework.web.multipart.commons.CommonsMultipartResolver"
    id="multipartResolver" />

数据访问失败
未找到资源
未找到资源
未找到资源
我的应用程序上下文

<context:annotation-config />

<context:property-placeholder location="classpath*:META-INF/spring/*.properties" />

<context:spring-configured />

<context:component-scan base-package="br.ufsc.inf.citymobile">
    <context:exclude-filter expression=".*_Roo_.*"
        type="regex" />
    <context:exclude-filter expression="org.springframework.stereotype.Controller"
        type="annotation" />
</context:component-scan>

<bean class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close" id="dataSource">
    <property name="driverClassName" value="${database.driverClassName}" />
    <property name="url" value="${database.url}" />
    <property name="username" value="${database.username}" />
    <property name="password" value="${database.password}" />
    <property name="testOnBorrow" value="true" />
    <property name="testOnReturn" value="true" />
    <property name="testWhileIdle" value="true" />
    <property name="timeBetweenEvictionRunsMillis" value="1800000" />
    <property name="numTestsPerEvictionRun" value="3" />
    <property name="minEvictableIdleTimeMillis" value="1800000" />
</bean>

<bean class="org.springframework.orm.jpa.JpaTransactionManager"
    id="transactionManager">
    <property name="entityManagerFactory" ref="entityManagerFactory" />
</bean>

<tx:annotation-driven mode="aspectj"
    transaction-manager="transactionManager" />

<bean
    class="org.springframework.orm.jpa.LocalContainerEntityManagerFactoryBean"
    id="entityManagerFactory">
    <property name="persistenceUnitName" value="persistenceUnit" />
    <property name="dataSource" ref="dataSource" />
</bean>

您的Spring版本太旧了

异常是抱怨缺少一个方法(
RequestMapping.consume
),该方法只在Spring3.1中引入,而不是在Spring3.0中引入


你需要升级到Spring 3.1

我从你的XML文件中删除了大量的注释。它们对可读性没有任何作用。哼,有趣的是,我现在的配置@3.1.0.RELEASE我会尝试更改版本。@Lucas:你的类路径上可能有重复的,不知怎的,有多个Spring版本。确切地说,我复制了,哼,可能有些库复制了SpringWeb和SpringTX,它们被复制为3.0.6版和3.1.0版-所以,谢谢你们,从来没有想过这一点。