Anatoly
Anatoly

Reputation: 1591

Vaadin 7 Servlet ClassCastException

I'm trying to migrate from Vaadin 6 to Vaadin 7.
When I'm trying to open application url I get a ClassCastException

SEVERE: Allocate exception for servlet Vaadin Application Servlet
java.lang.ClassCastException: com.vaadin.server.VaadinServlet cannot be cast to javax.servlet.Servlet
    at org.apache.catalina.core.StandardWrapper.loadServlet(StandardWrapper.java:1136)
    at org.apache.catalina.core.StandardWrapper.allocate(StandardWrapper.java:857)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:136)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:123)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:472)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:168)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:99)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:929)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:118)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:407)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1002)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:585)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:310)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at java.lang.Thread.run(Unknown Source)

I cann't understand what's wrong because it seems that web.xml is ok. Mapping of application servlet is listed below

 <servlet>
        <servlet-name>Ohta Application</servlet-name>
        <servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
        <init-param>
            <description>
        Vaadin UI class to use</description>
            <param-name>UI</param-name>
            <param-value>com.ritmsoft.ohta.OhtaUI</param-value>
        </init-param>
        <init-param>
            <param-name>widgetset</param-name>
            <param-value>com.ritmsoft.ohta.widgetset.OhtaWidgetSet</param-value>
        </init-param>
    </servlet>
    <servlet-mapping>
        <servlet-name>Ohta Application</servlet-name>
        <url-pattern>/*</url-pattern>
    </servlet-mapping>
    <servlet-mapping>
        <servlet-name>Ohta Application</servlet-name>
        <url-pattern>/VAADIN/*</url-pattern>
    </servlet-mapping>

Help me, please.

Upvotes: 4

Views: 2766

Answers (3)

dredg189
dredg189

Reputation: 39

I have the same issue here, but only if I try to run the vaadin maven project with the tomcat plugin for eclipse. The dependency for the serlet-api is exactly as shown above. Snd tehr eis no difference if I comment it completely or just the scope part. There is always a servlet-api-2.5-6.1.11 in the lib folder. I don't know from where this comes from. But with the scope provided there is definitly no javax.servlet-api.jar in the lib folder. And if i copy the war manuelly into the tomcats webapps folder and start if by console it works fine. I don't get the difference. Any ideas?

Upvotes: 0

CorayThan
CorayThan

Reputation: 17825

Or if you use Maven make your servlet's scope "provided" like so:

    <dependency>
        <groupId>javax.servlet</groupId>
        <artifactId>javax.servlet-api</artifactId>
        <version>3.0.1</version>
        <scope>provided</scope>
    </dependency>

That way it will use the container's version of the servlet jar if it exists, otherwise it will use the one you declare in Maven.

Upvotes: 2

Ajay
Ajay

Reputation: 763

The problem is most likely caused by javax.servlet.Servlet being loaded by multiple class-loaders. It usually exists in servlet*.jar. It is possible that the container provides its own version of this jar, and your application provides another. Try removing the one in your war.

Upvotes: 1

Related Questions