Jersey facing Servlet Javak

I am creating a simple REST service with Jersey and Maven. For Jersey versions greater than 1.8, web.xml in IntelliJ raises this error:

'com.sun.jersey.spi.container.servlet.ServletContainer' is not assignable to 'javax.servlet.Servlet' 

Does anyone know how to fix this to use the latest version of jersey?

This is web.xml

 <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" version="2.5"> <display-name>R Proxy</display-name> <context-param> <param-name>contextConfigLocation</param-name> <param-value>/WEB-INF/applicationContext.xml</param-value> </context-param> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/r-proxy-log4j.properties</param-value> </context-param> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> <!-- Jersey configuration --> <servlet> <servlet-name>jersey-servlet</servlet-name> <servlet-class>com.sun.jersey.spi.spring.container.servlet.SpringServlet</servlet-class> <init-param> <param-name>com.sun.jersey.config.property.packages</param-name> <param-value>org.fao.fenix.r.proxy.rest</param-value> </init-param> <load-on-startup>1</load-on-startup> </servlet> <listener> <listener-class>org.springframework.web.util.Log4jConfigListener</listener-class> </listener> <!-- Jersey configuration --> <servlet-mapping> <servlet-name>jersey-servlet</servlet-name> <url-pattern>/rest/*</url-pattern> </servlet-mapping> 

+4
source share
3 answers

For everyone who has the same problem, this is because you don't have the api servlet in your classpath. Just add the servlet-api dependency to your project and everything will be fine.

+2
source

I also studied this. Here is what I found, hope it can help others:

  • You may have the wrong servlet class in your web.xml. For Jersey 2.0 and above, you should use the group "org.glassfish" instead of the old "com.sun.jersey". So, inside your web.xml you should have:

     <servlet> ... <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class> </servlet> 
  • I ran into this problem again when I inadvertently used different versions of Jersey in the same project. My project imported the Jersey 1.9 package through Maven, but my code editor had a different version of Jersey on the way to the project class. Clear your class path, reimport what you need and check your jersey versions and it can solve your problem.

+1
source

The error corresponds to the fact that you should add dependencies that are busy com.sun.jersey.spi.container.servlet.ServletContainer

enter image description here

0
source

All Articles