404 error with Jersey REST Service on Tomcat

老子叫甜甜 提交于 2019-12-01 10:52:22
Paul Samsotha

"I am using Jersey 2.17"

This does not exist in 2.17

com.sun.jersey.spi.container.servlet.ServletContainer

I'm surprised you're not getting a class not found exception. Which means you are probably mixing versions. Or maybe you're getting an exception an not telling us. In any case, the correct ServletContainer should be

org.glassfish.jersey.servlet.ServletContainer

Next what you should do, if you have any, is get rid of everything (jar) whose packages begin with com.sun. These are Jersey 1 jars. In Jersey two, the package naming pattern changed to org.glassfish.xxx If you want to make life easy, use Maven, and simply add just one dependency to whole project, and it will pull in all the rest.

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

Also, this doesn't exist in Jersey two either

jersey.api.json.POJOMappingFeature

In Jersey 2, simply add this Maven depedency, and life will be good.

<dependency>
    <groupId>org.glassfish.jersey.media</groupId>
    <artifactId>jersey-media-json-jackson</artifactId>
    <version>2.17</version>
</dependency>

If you're not using Maven, download the RI bundle here. Open all the folders and add every jar to your project. This is for core support.

For JSON support, download this, as well as all of these. You can search the same site for them. doing this should work with no extra configuration. Alternatively, you can just download only the ones in the second link, then add the package in the web.xml, as seen in the link.

But just to get it working, since your code doesn't produce or consume any JSON, you can simply get the core running first, then once it starts working correctly, you can work on the JSON support.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!