RepositoryRestMvcConfiguration 无法转换为 javax.servlet.Servlet

RepositoryRestMvcConfiguration cannot be cast to javax.servlet.Servlet

我正在尝试将一个 war 文件部署到 tomcat,但日志文件显示以下异常:

SEVERE: Servlet [rest] in web application [/sample] threw load() exception
java.lang.ClassCastException: org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration cannot be cast to javax.servlet.Servlet
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1148)
    at org.apache.catalina.core.StandardWrapper.load(StandardWrapper.java:1087)
    at org.apache.catalina.core.StandardContext.loadOnStartup(StandardContext.java:5253)
    at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5543)
    at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
    at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:901)
    at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:877)
    at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:652)
    at org.apache.catalina.startup.HostConfig.deployWAR(HostConfig.java:1095)
    at org.apache.catalina.startup.HostConfig$DeployWar.run(HostConfig.java:1930)
    at java.util.concurrent.Executors$RunnableAdapter.call(Unknown Source)
    at java.util.concurrent.FutureTask.run(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

这是 build.gradle 文件

repositories {

    mavenCentral()
}

dependencies {
   providedCompile   'org.apache.tomcat:tomcat-servlet-api:7.0.37'
   providedCompile   'javax.servlet:javax.servlet-api:4.0.0-b01'

    // Spring Framework Jars 
    compile 'org.springframework:spring-context:4.1.0'
    compile 'org.springframework.ws:spring-ws-core:2.2.2.RELEASE'
    compile 'org.springframework.data:spring-data-jpa:1.9.0.RELEASE'


    // Spring Integration Jars
    compile 'org.springframework.integration:spring-integration-core:4.1.2.RELEASE'
    compile 'org.springframework.integration:spring-integration-stream:4.1.2.RELEASE'
    compile 'org.springframework.integration:spring-integration-jms:4.1.2.RELEASE'
    compile 'org.springframework.integration:spring-integration-xml:4.1.2.RELEASE'
    compile 'org.springframework.integration:spring-integration-http:4.1.2.RELEASE'
    compile 'org.springframework.integration:spring-integration-mail:4.1.2.RELEASE'
    compile 'org.springframework:spring-webmvc:4.2.2.RELEASE'
    compile 'org.springframework.data:spring-data-rest-webmvc:2.4.0.RELEASE'
    // Spring Batch Framework Jars
    compile 'org.springframework.batch:spring-batch-infrastructure:3.0.4.RELEASE' 
    compile 'org.springframework.batch:spring-batch-core:3.0.4.RELEASE'

    // Log4j Jar
    compile 'log4j:log4j:1.2.17'

    // IBM JMS MQ Jars
    compile 'com.ibm:com.ibm.mq:7.0.1.0'
    compile 'com.ibm:com.ibm.mq.jmqi:7.0.1.0'
    compile 'com.ibm:com.ibm.mqjms:7.0.1.0'
    compile 'javax.jms:jms-api:1.1-rev-1'


    // Hibernate JARS
    compile 'org.hibernate:hibernate-entitymanager:5.0.1.Final'

    //Oracle JDBC Jar 
    compile 'com.oracle:ojdbc6:11.2.0.3.0'

    //Mail Jar
     compile 'javax.mail:javax.mail-api:1.5.4'


} 

这是我的 web.xml 文件。

<web-app>
<display-name>sample Web Application</display-name>
<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener
    </listener-class>
</listener>
<listener>
<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>WEB-INF/config/sample-servlet.xml</param-value>
</context-param>

<servlet>
    <servlet-name>rest</servlet-name>
    <servlet-class>org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration
    </servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>

<servlet-mapping>
    <servlet-name>rest</servlet-name>
    <url-pattern>/api/*</url-pattern>
</servlet-mapping>

我试图排除 "javax.servlet-api ",但无济于事。

如果有人能帮我找到这个异常背后的原因,那将有很大帮助。

谢谢

犯了一个愚蠢的错误,而不是使用

"org.springframework.data.rest.webmvc.RepositoryRestDispatcherServlet"

,我用了

"org.springframework.data.rest.webmvc.config.RepositoryRestMvcConfiguration"

.

希望大家看到后post不要再犯同样的错误