简体   繁体   English

在TomEE中使用Jersey RESTful Web服务

[英]Using Jersey RESTful web service with TomEE

I'm facing some problems running a simple RESTful web service with Jersey with a TomEE server. 我在使用带有TomEE服务器的Jersey运行简单的RESTful Web服务时遇到了一些问题。 (This is the tutorial i'm following: http://www.vogella.com/tutorials/REST/article.html though I'm using Maven for my dependencies and TomEE JAX-RS as my server). (这是我正在遵循的教程: http ://www.vogella.com/tutorials/REST/article.html虽然我使用Maven作为我的依赖项,而TomEE JAX-RS作为我的服务器)。 When I run the server, I get the following error: 当我运行服务器时,我收到以下错误:

org.apache.openejb.OpenEJBException: Unable to load servlet class: org.glassfish.jersey.servlet.ServletContainer: org.glassfish.jersey.servlet.ServletContainer
at org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.deploy(AnnotationDeployer.java:2113)
at org.apache.openejb.config.AnnotationDeployer$ProcessAnnotatedBeans.deploy(AnnotationDeployer.java:1843)
at org.apache.openejb.config.AnnotationDeployer.deploy(AnnotationDeployer.java:360)
at org.apache.openejb.config.ConfigurationFactory$Chain.deploy(ConfigurationFactory.java:401)
at org.apache.openejb.config.ConfigurationFactory.configureApplication(ConfigurationFactory.java:962)
at org.apache.tomee.catalina.TomcatWebAppBuilder.startInternal(TomcatWebAppBuilder.java:1214)
at org.apache.tomee.catalina.TomcatWebAppBuilder.configureStart(TomcatWebAppBuilder.java:1087)
at org.apache.tomee.catalina.GlobalListenerSupport.lifecycleEvent(GlobalListenerSupport.java:130)
at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:117)
at org.apache.catalina.util.LifecycleBase.fireLifecycleEvent(LifecycleBase.java:90)
at org.apache.catalina.core.StandardContext.startInternal(StandardContext.java:5378)
at org.apache.catalina.util.LifecycleBase.start(LifecycleBase.java:150)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1575)
at org.apache.catalina.core.ContainerBase$StartChild.call(ContainerBase.java:1565)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)

The servlet class is derived from my web.xml file: servlet类派生自我的web.xml文件:

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee"  xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd" version="3.0">
<display-name>RestTest</display-name>
  <servlet>
    <servlet-name>Jersey REST Service</servlet-name>
    <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
    <!-- Register resources and providers under com.vogella.jersey.first package. -->
    <init-param>
      <param-name>jersey.config.server.provider.packages</param-name>
      <param-value>com.vogella.jersey.first</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>
  </servlet>
  <servlet-mapping>
    <servlet-name>Jersey REST Service</servlet-name>
    <url-pattern>/rest/*</url-pattern>
  </servlet-mapping>

</web-app>

And these are my dependencies in the project's maven pom.xml file: 这些是我在项目的maven pom.xml文件中的依赖项:

<dependency>
    <groupId>org.glassfish.jersey.containers</groupId>
    <artifactId>jersey-container-servlet</artifactId>
    <version>2.14</version>
    <scope>provided</scope>
</dependency>
<dependency>
    <groupId>org.glassfish.jersey.core</groupId>
    <artifactId>jersey-client</artifactId>
    <version>2.14</version>
    <scope>provided</scope>
</dependency>

This is my first time using a TomEE JAX-RS server, (and on top of that, I've been using microsoft server technology for the past few years), so please comment if I havn't supplied enough information for you to work on a solution. 这是我第一次使用TomEE JAX-RS服务器(最重要的是,过去几年我一直在使用微软服务器技术),所以如果我没有提供足够的信息供你工作,请发表评论解决方案。

You shouldn't use provided scope for your Jersey dependencies. 您不应该为Jersey依赖项使用provided范围。

provided indicates that the dependency is provided by the runtime environment (ie TomEE) and should not be included in your web app. provided指示的依赖性由运行时环境(即TomEE)提供的,不应该被包含在你的web应用程序。 But that's not the case with TomEE. 但TomEE的情况并非如此。

TomEE web profile does not include JAX-RS at all. TomEE Web配置文件根本不包含JAX-RS。 TomEE Plus includes CXF for JAX-RS, but not Jersey. TomEE Plus包括用于JAX-RS的CXF,但不包括Jersey。

Anyway, Jersey 2.x implements JAX-RS 2.0 for Java EE 7, but TomEE is Java EE 6, so you shouldn't expect your use case to work out of the box. 无论如何,Jersey 2.x为Java EE 7实现了JAX-RS 2.0,但是TomEE是Java EE 6,因此您不应期望您的用例能够开箱即用。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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