我在使用带有TomEE服务器的Jersey运行简单的RESTful Web服务时遇到了一些问题。 (这是我正在遵循的教程:http://www.vogella.com/tutorials/REST/article.html虽然我使用Maven作为我的依赖项,而TomEE JAX-RS作为我的服务器)。当我运行服务器时,出现以下错误:
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)
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>
这些是我在项目的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>
这是我第一次使用TomEE JAX-RS服务器(最重要的是,过去几年我一直在使用微软服务器技术),所以如果我没有提供足够的信息,请发表评论你要解决这个问题。
答案 0 :(得分:6)
您不应该将provided
范围用于您的Jersey依赖项。
provided
表示依赖项由运行时环境(即TomEE)提供,不应包含在您的Web应用程序中。但是,TomEE的情况并非如此。
TomEE网络个人资料根本不包含JAX-RS。 TomEE Plus包括用于JAX-RS的CXF,但不包括Jersey。
无论如何,Jersey 2.x为Java EE 7实现了JAX-RS 2.0,但TomEE是Java EE 6,因此您不应期望您的用例开箱即用。