15

Tomcat サーバーの起動中に例外が発生します

SEVERE: Servlet /MavenWeb threw load() exception
java.lang.ClassCastException: org.springframework.web.servlet.DispatcherServlet
cannot be cast to javax.servlet.Servlet

spring3 を使用していますが、lib フォルダーに jar spring2-5-6 があり、pom.xml から削除しましたが、lib フォルダーにはまだ表示されていますが、それが問題かどうかはわかりません。私はEclipse IDEを使用しています。ありがとう!!

<dependencies>
    <dependency>
      <groupId>org.hibernate.javax.persistence</groupId>
      <artifactId>hibernate-jpa-2.1-api</artifactId>
      <version>1.0.0.Draft-6</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.hibernate</groupId>
      <artifactId>hibernate-annotations</artifactId>
      <version>3.5.6-Final</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-beans</artifactId>
      <version>3.1.2.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-context</artifactId>
      <version>3.1.2.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-web</artifactId>
      <version>3.1.2.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-tx</artifactId>
      <version>3.1.2.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webmvc</artifactId>
      <version>3.1.2.RELEASE</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>javax.servlet</groupId>
      <artifactId>javax.servlet-api</artifactId>
      <version>3.1-b01</version>
      <scope>compile</scope>
    </dependency>
    <dependency>
      <groupId>org.springframework</groupId>
      <artifactId>spring-webflow</artifactId>
      <version>1.0.6</version>
      <scope>compile</scope>
    </dependency>
  </dependencies>
4

2 に答える 2

29

1つのプロジェクトで複数のバージョンのSpringJARを使用するべきではありませんが、これは問題ではありません。

この問題は、2つの異なるクラスローダーによってロードされたサーブレットAPIクラスが原因である可能性があります。おそらくservlet*.jar、WARにまたは他のコンテナ固有のJARがあります。<scope>に設定して削除しprovidedますpom.xml

于 2012-07-28T19:45:52.793 に答える
0

In my case it wasn't a problem with the libraries. I was changing a Standard Servlet to be implemented with Spring, so I followed these instructions, that I paraphrase here just in case the page goes down later:

  1. Implement org.springframework.web.HttpRequestHandler instead of extending javax.Servlet

    public class MyServlet implements HttpRequestHandler {

  2. Created the bean in the applicationContext.xml (I did it in the dispatcher-servlet.xml)

    <bean id="MyServlet" class="com.package.to.MyServlet"/>

  3. Specify the servlet in the Web.xml, changing the old class (com.package.to.MyServlet) to Spring HttpRequestHandlerServlet.

    <servlet> <servlet-name>MyServlet</servlet-name> <servlet-class>org.springframework.web.context.support.HttpRequestHandlerServlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>MyServlet</servlet-name> <url-pattern>/MyServlet</url-pattern> </servlet-mapping>

I had to do an additional step to avoid a FileNotFoundException about applicationContext.xml doing the following in the web.xml

<context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/dispatcher-servlet.xml</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener>

于 2013-04-08T21:14:54.647 に答える