泽西与Jetty艰难时刻

时间:2013-09-11 03:05:55

标签: java rest jersey jetty embedded-jetty

我无法使用嵌入式Jetty 7和Jersey运行我的RESTful服务。当我打电话给我简单的问候测试时,我得到:

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。任何提示?我的init服务器代码:

    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>

你有任何提示吗?

1 个答案:

答案 0 :(得分:0)

jersey-server兑换为:

<dependency>
   <groupId>com.sun.jersey</groupId>
   <artifactId>jersey-bundle</artifactId>
   <version>1.11.1</version>
</dependency>