WSSpringServlet无法强制转换为javax.servlet.Servlet

时间:2015-10-18 00:54:18

标签: java spring maven tomcat

我正在使用带有tomcat的spring构建一个Web服务。

我正在创建一个WSSpringServlet来监听请求,但每次类强制转换异常时都会说: com.sun.xml.ws.transport.http.servlet.WSSpringServlet无法强制转换为javax.servlet.Servlet

这是web.xml

<web-app id="WebApp_ID" version="2.4" 
xmlns="http://java.sun.com/xml/ns/j2ee" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">

<display-name>Spring + JAX-WS</display-name>

<servlet>
            <servlet-name>jaxws-servlet</servlet-name>
           <servlet-class>
                  com.sun.xml.ws.transport.http.servlet.WSSpringServlet
            </servlet-class>
</servlet>

<servlet-mapping>
            <servlet-name>jaxws-servlet</servlet-name>
            <url-pattern>/hello</url-pattern>
     </servlet-mapping>

     <!-- Register Spring Listener -->
<listener>
            <listener-class>
             org.springframework.web.context.ContextLoaderListener
            </listener-class>
</listener>

,pom.xml是

<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>com.dev.backend</groupId>
<artifactId>Code</artifactId>
<packaging>war</packaging>
<version>1.0-SNAPSHOT</version>
<name>Code Maven Webapp</name>
<url>http://maven.apache.org</url>
<dependencies>
    <dependency>
        <groupId>junit</groupId>
        <artifactId>junit</artifactId>
        <version>3.8.1</version>
        <scope>test</scope>
    </dependency>

    <!-- Spring framework -->
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring</artifactId>
        <version>2.5.6</version>
    </dependency>
    <dependency>
        <groupId>org.springframework</groupId>
        <artifactId>spring-web</artifactId>
        <version>2.5.6</version>
    </dependency>
    <!-- Spring AOP dependency -->
    <dependency>
        <groupId>cglib</groupId>
        <artifactId>cglib</artifactId>
        <version>2.2</version>
    </dependency>

    <!-- MySQL database driver -->
    <dependency>
        <groupId>mysql</groupId>
        <artifactId>mysql-connector-java</artifactId>
        <version>5.1.9</version>
    </dependency>

    <!-- Hibernate framework -->


    <!-- Hibernate annotation -->


    <!-- Hibernate library dependecy start -->
    <dependency>
        <groupId>dom4j</groupId>
        <artifactId>dom4j</artifactId>
        <version>1.6.1</version>
    </dependency>

    <dependency>
        <groupId>commons-logging</groupId>
        <artifactId>commons-logging</artifactId>
        <version>1.1.1</version>
    </dependency>

    <dependency>
        <groupId>commons-collections</groupId>
        <artifactId>commons-collections</artifactId>
        <version>3.2.1</version>
    </dependency>

    <dependency>
        <groupId>antlr</groupId>
        <artifactId>antlr</artifactId>
        <version>2.7.7</version>
    </dependency>
    <!-- Hibernate library dependecy end -->

    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate</artifactId>
        <version>3.2.3.ga</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-annotations</artifactId>
        <version>3.3.0.ga</version>
    </dependency>
    <dependency>
        <groupId>org.hibernate</groupId>
        <artifactId>hibernate-commons-annotations</artifactId>
        <version>3.0.0.ga</version>
    </dependency>
    <dependency>
        <groupId>javax.transaction</groupId>
        <artifactId>jta</artifactId>
        <version>1.1</version>
    </dependency>
    <!-- JAX-WS -->


    <!-- Library from java.net, integrate Spring with JAX-WS -->
    <dependency>
        <groupId>org.jvnet.jax-ws-commons.spring</groupId>
        <artifactId>jaxws-spring</artifactId>
        <version>1.6</version>
        <exclusions>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-core</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.springframework</groupId>
                <artifactId>spring-context</artifactId>
            </exclusion>
            <exclusion>
                <groupId>com.sun.xml.stream.buffer</groupId>
                <artifactId>streambuffer</artifactId>
            </exclusion>
            <exclusion>
                <groupId>org.jvnet.staxex</groupId>
                <artifactId>stax-ex</artifactId>
            </exclusion>
        </exclusions>
    </dependency>



    <dependency>
        <groupId>com.sun.xml</groupId>
        <artifactId>jaxws-rt</artifactId>
        <version>2.0EA3</version>
    </dependency>
    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>servlet-api</artifactId>
        <version>2.5</version>
    </dependency>
</dependencies>
<build>
    <finalName>Code</finalName>
    <plugins>
        <plugin>
            <groupId>org.apache.maven.plugins</groupId>
            <artifactId>maven-compiler-plugin</artifactId>
            <version>2.3.1</version>
            <configuration>
                <source>1.6</source>
                <target>1.6</target>
            </configuration>
        </plugin>
    </plugins>
</build>

编辑:我正在运行tomcat 8我将尝试使用tomcat7,看看会发生什么。

Edit2:我正在使用命令“mvn tomcat:run”所以我尝试添加一个继承HttpServlet类的我自己的servlet,同样的错误发生在说 java.lang.ClassCastException: com.dev.backend.services.Hi无法强制转换为javax.servlet.Servlet 这意味着我认为tomcat或该命令出了问题。

有人可以帮忙吗?

0 个答案:

没有答案