在 Tomcat 上使用 RESTeasy

Using RESTeasy on Tomcat

我是 restful 网络的新手 services.One 我的客户给了我一些带有 resteasy 实现的方法 我在我的 project.I 中使用的那些方法正在使用 apache tomcat我 project.can 中的服务器 这些方法是否会 运行 在 apache tomcat 服务器上???

是的,这是可能的。您需要添加 RESTeasy 实现 jars/dependencies.

对于 Maven (resteasy.version == 3.0.9.Final)

<!-- Basic support -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jaxrs</artifactId>
    <version>${resteasy.version}</version>
</dependency>
<!-- Servlet pluggability support -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-servlet-initializer</artifactId>
    <version>${resteasy.version}</version>
</dependency>
<!-- JSON/POJO support -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-jackson2-provider</artifactId>
    <version>${resteasy.version}</version>
</dependency>
<!-- REST Client support -->
<dependency>
    <groupId>org.jboss.resteasy</groupId>
    <artifactId>resteasy-client</artifactId>
    <version>${resteasy.version}</version>
</dependency>

您可以在下面看到 Maven 依赖项引入的所有 jar 和传递 jar(如果您不使用 Maven)。

您可以方便地下载分发 here, which comes with all the jars. Also keep the Documentation。我没有包含发行版附带的所有依赖项。其他功能需要一些依赖项。如果你愿意,你可以添加所有的罐子(来自发行版),但我只是向你展示它所需要的基础知识。

你也要注意版本。 3.x 和 2.x 系列工作不同的 API,因此您可能需要弄清楚您到底需要哪一个。我提供的链接包含所有版本的分发和文档。为了这个答案,我只使用了 3.0.9.Final.

另一件事,发行版附带了一堆可能会派上用场的例子。尽管所有示例都需要 Maven。


更新

有了上面的jars/dependencies,就可以搞定一个简单的app了运行,只需

@ApplicationPath("/rest")
public class WebConfig extends Application {
}

@Path("/simple")
public class SimpleResource {

    @GET
    @Produces(MediaType.TEXT_PLAIN)
    public String getTest() {
        return "Hello REST World!";
    }
}

不需要额外的 (web.xml) 配置。使用带有 @ApplicationPath 注释的空 Application class,所有带有 @Path 的 class 将被注册为资源 class。这是通过 resteasy-servlet-initializer 实现的,它脱离了 servlet 可插拔机制。


编辑

在图像中,javaee-web-api 罐子不应该在那里。我一定是创建了一个新的 maven web 项目,当我尝试创建图像时,其中包含它。