0

我无法使用嵌入式 Jetty 7 和 Jersey 运行我的 RESTful 服务。当我调用我的简单 hello 测试时,我得到:

javax.ws.rs.WebApplicationException: com.sun.jersey.api.MessageException: A message
body writer for     Java class java.lang.String, and Java type class java.lang.String,
and MIME media type text/plain was    not found

我在 SO 上看到了类似的错误,但它是针对自定义类的,而我的只是针对String. 有什么提示吗?我的初始化服务器代码:

    ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS);
    context.setContextPath("/");
    server.setHandler(context);
    ServletContainer container = new ServletContainer();
    ServletHolder h = new ServletHolder(container);
    h.setInitParameter("com.sun.jersey.config.property.packages", "api");
    context.addServlet(h, "/res/*");

和依赖:

<dependency>
    <groupId>com.sun.jersey</groupId>
    <artifactId>jersey-server</artifactId>
    <version>1.11.1</version>
</dependency>
<dependency>
                <groupId>org.eclipse.jetty</groupId>
                <artifactId>jetty-server</artifactId>
                <version>7.1.6.v20100715</version>
</dependency>

你有什么提示吗?

4

1 回答 1

0

交换jersey-server至:

<dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-bundle</artifactId>
   <version>1.11.1</version>
</dependency>
于 2013-09-11T12:14:13.890 回答