0

I am trying to deploy a RESTful web service in JBOSS7.1.1 and it is giving me the error below: ERROR [org.apache.catalina.core.ContainerBase.[jboss.web].[default-host].[/anthut]] (MSC service thread 1-1) Servlet /anthut threw load() exception: java.lang.ClassCastException: com.sun.jersey.spi.spring.container.servlet.SpringServlet cannot be cast to javax.servlet.Servlet.

The version of jersey that I am using in my project is 1.18.3.

A section of my web.xml is given below

 <listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
 <servlet>
<servlet-name>abdfserve</servlet-name>
<servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class>

please what could be responsible for this, I have being on this for some days now...I need help please..

jcjoof
  • 33
  • 9
  • 1
    Do you have multiple versions of the servlet API on you classpath? You should not have any additional servlet-api.jar. JBOSS already provides that. – Thilo Jan 19 '15 at 08:41
  • I should take it out of my dependency? – jcjoof Jan 19 '15 at 08:45
  • You need it as a compile-time dependency, but it should not be deployed. If you use Maven, it has "provided" scope. – Thilo Jan 19 '15 at 08:46
  • Yes, I use Maven and it has provided scope. – jcjoof Jan 19 '15 at 09:13
  • Thank you @Thilo, indeed I duplicated servlet API in my JBOSS modules settings; I made it dependencies in two modules that I used in my project, as I removed it from one, the issue got resolved. – jcjoof Jan 20 '15 at 11:54
  • possible duplicate of [ClassCastException: MyFilter cannot be cast to javax.servlet.Filter](http://stackoverflow.com/questions/15119712/classcastexception-myfilter-cannot-be-cast-to-javax-servlet-filter) – Thilo Jan 20 '15 at 12:01
  • possible duplicate of [ServletDispatcher cannot be cast to Javax.servlet.Servlet exception in my spring project](http://stackoverflow.com/questions/11704069/servletdispatcher-cannot-be-cast-to-javax-servlet-servlet-exception-in-my-spring) – Oleg Estekhin Feb 10 '15 at 20:16

1 Answers1

0

This can happen when you have multiple versions of the servlet API in your classpath.

The servlet API is always provided by the web application server, you must not include it in your own web application bundles.

You need it as a compile-time dependency during development, but it should not be deployed. If you use Maven, make sure it has "provided" scope.

Thilo
  • 257,207
  • 101
  • 511
  • 656