简体   繁体   中英

Jersey 2 servlet 404 issue

I have read all topics related to my issue but solution still not found. The problem is that when i use this dependency in pom.xml
<dependency> <groupId>com.sun.jersey</groupId> <artifactId>jersey-servlet</artifactId> <version>1.19.1</version> </dependency>

and this serlvet mapping in web.xml

<servlet>
        <servlet-name>Jersey Web Application</servlet-name>
        <servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
        <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
        <servlet-name>Jersey Web Application</servlet-name>
        <url-pattern>/*</url-pattern>
</servlet-mapping> 

everything works correctly.

But when i change dependency to:

<dependency>
            <groupId>org.glassfish.jersey.core</groupId>
            <artifactId>jersey-server</artifactId>
            <version>2.22.2</version>
</dependency>

and servlet mapping to:

<servlet>
        <servlet-name>jerseyServlet</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>jersey.config.server.provider.packages</param-name>
            <param-value>com.myApp</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
        <servlet-name>jerseyServlet</servlet-name>
        <url-pattern>/*</url-pattern>
</servlet-mapping>

then Tomcat give me 404 error. The main cause for using second config entry is that i need async support, and as i understand this is possible only in Jersey 2.x Can anyone help me to solve this issue?

You need the Jersey servlet dependency

<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <version>2.22.2</version>
</dependency>

Also for async support, you should also add <async-supported>true</async-supported> to your Jersey servlet declaration

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM