【问题标题】:Does WebSphere 8.5 have built in JAX-RS handling?WebSphere 8.5 是否内置了 JAX-RS 处理?
【发布时间】:2015-02-09 16:41:33
【问题描述】:

关于 IBM 支持的多个页面在 JAX-RS 是否内置于 WebSphere 8.5 方面似乎有所不同。

http://www.ibm.com/developerworks/websphere/techjournal/1305_gunderson/1305_gunderson.html

最新版本的 IBM WebSphere Application Server 提供对 JAX-RS 的支持。 WebSphere Application Server V8.5 内置了对 JAX-RS 的支持;无需额外安装。

http://www-01.ibm.com/support/knowledgecenter/SSAW57_8.5.5/com.ibm.websphere.nd.iseries.doc/ae/twbs_jaxrs_devenv.html?cp=SSAW57_8.5.5%2F2-13-2-38-1-1&lang=en

要开发 JAX-RS 应用程序,必须将 JAX-RS 库添加到类路径定义中。请参阅有关您的组装工具的信息,以了解如何在 JAX-RS 应用程序的类路径中包含库。

在 WebSphere 8.5 上运行 JAX-RS 需要做什么。是否需要 web.xml 映射?是否需要额外的库文件?

【问题讨论】:

    标签: java websphere jax-rs


    【解决方案1】:

    WebSphere 8.5.5 实现了 JAX-RS 1.1 提供程序,因此您不需要任何额外的库。您可以根据需要创建或不创建映射。您的选项的最佳描述在这里Configuring JAX-RS applications using JAX-RS 1.1 methods

    您可以:

    • 在 web.xml 文件中仅使用一个 JAX-RS 默认应用程序配置 JAX-RS 应用程序,如下所示:
    <servlet>
        <servlet-name>javax.ws.rs.core.Application</servlet-name>
    </servlet>
    <servlet-mapping>
      <servlet-name>javax.ws.rs.core.Application</servlet-name>
      <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
    
    • 使用 javax.ws.rs.core.Application 子类 web.xml 文件配置 JAX-RS 应用程序:
    <servlet>         
        <servlet-name>com.example.MyApplication</servlet-name> 
    </servlet>
    <servlet-mapping>
        <servlet-name>com.example.MyApplication</servlet-name>
        <url-pattern>/rest/*</url-pattern>
    </servlet-mapping>
    
    • 在没有 web.xml 文件的情况下配置 JAX-RS 应用程序。您只能使用 @ApplicationPath@Path 等注释
    @ApplicationPath("rest")
    public class MyApplication extends javax.ws.rs.core.Application {
    }
    
    @Path("/helloworld")
    public class HelloWorldResource {
    
        @GET
        public String sayHelloWorld() {
            return "Hello World!";
        }
    }
    

    【讨论】:

    • 谢谢,我想我在解决通过 IntelliJ 部署的类时遇到了问题。在我的例子中,我只是添加了第一个 web.xml 和资源,但我没有对java.ws.rs.core.Application 进行子类化。您发布的链接也很有帮助。
    • 嗨@Gas,也许你知道我应该怎么做才能将对 jax-rs 2.0 的支持添加到 WAS 8.5 完整配置文件?
    • @Anatoly 完整配置文件(现在称为传统 WAS)在 8.5.5.x 版本中不支持 JAX-RS 2.0。因此,您可以迁移到 WebSphere Liberty Profile,也可以包含第三方 JAX-RS 库。请参阅此处JAX-RS Jersey 2.10 support in Websphere 8 了解如何操作。
    • 我无法让 JAX-RS 1.1 与 WebSphere 8.5.5 一起使用能够使用 web.xml 文件。我对仅使用注释很感兴趣。你能像上面那样提供更多关于这方面的信息吗?您只是 Liberty Profile 的示例吗?
    • @ShawnStrickland - 如提供的链接中所述(这是完整的配置文件,也就是传统的 WAS) - 声明为The ApplicationPath annotation is supported with the JAX-RS 1.1 specification.,因此它应该与注释一起正常工作。尝试,如果您有问题,请发布另一个问题:-)
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2015-06-21
    • 2020-05-16
    • 1970-01-01
    • 2013-02-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多