问题描述
我尝试在Tomee 1.5.2 WebProfile中使用Jersey 1.18部署一个非常简单的RESTful Web服务.我的项目完全受 tomee-jersey-eclipselink
I attempt to deploy a very simple RESTful Web Service using Jersey 1.18 within Tomee 1.5.2 WebProfile.My project is fully inspired from the tomee-jersey-eclipselink
我通过删除持久性部分来进一步简化的示例:Web服务只是重新调优"Hello,World!"
example that I further simplified by removing the persistence part: the Web Service simply retuns "Hello, World!"
@Path("/hello")
@RequestScoped
public class HelloService {
public HelloService() {
}
@GET
public String test() {
return "Hello, World!";
}
}
我对POM的依赖性:
<dependencies>
<dependency>
<groupId>javax</groupId>
<artifactId>javaee-api</artifactId>
<version>6.0</version>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-server</artifactId>
<version>1.18</version>
</dependency>
<dependency>
<groupId>com.sun.jersey</groupId>
<artifactId>jersey-servlet</artifactId>
<version>1.18</version>
</dependency>
</dependencies>
我使用不可知的应用程序模型部署Web服务:
I deploy my Web Service with the agnostic Application model:
import javax.ws.rs.core.Application;
import java.util.HashSet;
import java.util.Set;
public class JerseyApplication extends Application {
@Override
public Set<Class<?>> getClasses() {
final Set<Class<?>> classes = new HashSet<Class<?>>();
classes.add(HelloService.class);
return classes;
}
}
这是我的web.xml:
And here is my web.xml:
<web-app>
<servlet>
<servlet-name>Jersey Web Application</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>javax.ws.rs.Application</param-name>
<param-value>org.superbiz.service.JerseyApplication</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>Jersey Web Application</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
我还在$ TOMEE/conf/system.properties中添加了以下属性:
I also added the following property in $TOMEE/conf/system.properties:
com.sun.jersey.server.impl.cdi.lookupExtensionInBeanManager=true
一切都可以在Tomcat 7上正常运行(在这种情况下,我在POM中用javax.enterprise:cdi-api:1.1替换了javax:javaee-api依赖项),但是当我尝试使用Tomee时,我得到的却是404 HTTP状态,无一例外,没有其他日志消息.
Everything works fine with Tomcat 7 (In this case, I replace the javax:javaee-api dependency by javax.enterprise:cdi-api:1.1 in the POM), but when I try with Tomee, I just get a 404 HTTP status, with no exception and no additional logging message.
每当我从Eclipse IDE或在命令行中使用Maven部署应用程序时,结果都是相同的.
The result is the same whenever I deploy the application from my Eclipse IDE or with Maven in command line.
注意:
- 我不想将Tomee JAX-RS与Apache CXF一起使用,并且我不能升级到Tomee 1.6.
- 我已经从帖子中尝试了所有可能的方法,没有帮助.
- I do not want to use Tomee JAX-RS with Apache CXF, and I cannotupgrade to Tomee 1.6.
- I already tried all possible ways from this post, that did not help.
有什么主意吗?
推荐答案
有一个问题在TomEE 1.7.0中已解决,从而解决了此问题.如问题所述,您还需要在catalina.properties中添加以下行:
There was an issue resolved in TomEE 1.7.0 that fixed this problem. As the issue notes, you also need to add the following line to your catalina.properties:
openejb.classloader.forced-load=javax.ws.rs
这对我和Jersey 2一起工作.
This worked for me with Jersey 2.
这篇关于如何将Jersey与TomEE集成?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!