404错误,tomcat 8上的Jersey 2.x [英] 404 error, Jersey 2.x on tomcat 8

查看:96
本文介绍了404错误,tomcat 8上的Jersey 2.x的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用Jersey 2.xtomcat 8来开发我的第一个RESTful Api,但是当我尝试使用我的资源时,会不断出现404错误.

I'm working on my first RESTful Api with Jersey 2.x and tomcat 8 but when I try to acceed to my Resources I keep getting a 404 errors.

这是我的 web.xml :

<?xml version="1.0" encoding="UTF-8"?>
<web-app 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://xmlns.jcp.org/xml/ns/javaee"
    xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
    id="WebApp_ID" 
    version="3.1">

    <servlet>
        <servlet-name>com.pj.api.application.Application</servlet-name>
    </servlet>
    <servlet-mapping>
        <servlet-name>com.pj.api.application.Application</servlet-name>
        <url-pattern>/api/*</url-pattern>
    </servlet-mapping>
</web-app>

我的应用类:

@ApplicationPath ("api")
public class Application extends ResourceConfig {

    public Application () {
        packages ("com.pj.api.resources");
    }   
}

我的资源类:

@Path ("value=/users")
public class UserResources extends ResourcesImpl {

    private UserDao user = new UserDao ();

    @Override
    public List<Data> getList () {
        return user.getList ();
    }

    @GET
    @Path ("value=/test")
    public String Test () {
        return "{'a':'hey'}";
    }

    @Override
    public Data get (String id) {
        return user.get (id);
    }

    @Override
    public void post (Data data) {
        user.post (data);
    }

    @Override
    public void put (Data data) {
        user.put (data);
    }

    @Override
    public void delete(Data data) {
        user.delete (data);
    }
}

在Tomcat上部署项目并通过URL进入服务时:http://localhost:8080/PJ/api/users/test它给我404错误和Cannot cast org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer to javax.servlet.ServletContainerInitializer

When deploying the project on Tomcat, and acceeding to the Service through the URL : http://localhost:8080/PJ/api/users/test it gives me a 404 error and Cannot cast org.glassfish.jersey.servlet.init.JerseyServletContainerInitializer to javax.servlet.ServletContainerInitializer

p.s :我不使用Maven

p.s : I do NOT use Maven

这里可能是什么问题?谢谢.

What could be the problem here ? Thank you.

推荐答案

这当然看起来像是类路径问题.您的服务器运行时是否包括一些默认的Jax-rs库?当尝试在包含jax-rs 1.1库的服务器上部署基于Jersey 2.4的应用程序时,我遇到了类似的问题,因此我不得不在Jersey 1.18上重建应用程序.在Eclipse中检查服务器运行时是否有任何现有库

This certainly looks like a classpath issue. Does your server runtime include some default Jax-rs libraries? I faced a similar issue when trying to deploy my app built on Jersey 2.4 on a server that included jax-rs 1.1 libraries, so I had to rebuild my app on Jersey 1.18. Check your server runtime in Eclipse for any existing libraries

这篇关于404错误,tomcat 8上的Jersey 2.x的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆