泽西岛的码头在Android上抛出ContainerException:本ResourceConfig实例不包含任何根资源类 [英] Jersey on Jetty on Android throws ContainerException: The ResourceConfig instance does not contain any root resource classes

查看:651
本文介绍了泽西岛的码头在Android上抛出ContainerException:本ResourceConfig实例不包含任何根资源类的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在Android上运行的码头新泽西州。

I'm trying to run Jersey on Jetty on Android.

我已经创建了一个Android的实例化一个Jetty服务器与新泽西州的Servlet。反正当我开始Jetty和访问REST资源(在我的情况: http://192.168.1.12:8080/api/hello )我得到消息ContainerException:中ResourceConfig实例不包含任何根资源类。 (见下面的异常堆栈跟踪)。

I've created an Android that instantiate a Jetty Server with a Jersey Servlet. Anyway when I start Jetty and visit a REST resource (in my case: http://192.168.1.12:8080/api/hello) I get a ContainerException with message: The ResourceConfig instance does not contain any root resource classes. (see exception stack trace below).

任何想法,为什么?

更多详情:

的logcat是给下面的SEVER警告。

Logcat is giving the following SEVER WARNINGS.

下面的错误和警告已经被检测到的资源和/或提供者类:

The following errors and warnings have been detected with resource and/or provider classes:

严重:缺少相关的领域:私人java.lang.ThreadLocal中com.sun.jersey.server.impl.container.servlet.JSPTemplateProcessor.requestInvoker 重度:缺少相关的领域:私人java.lang.ThreadLocal中com.sun.jersey.server.impl.container.servlet.JSPTemplateProcessor.requestInvoker

SEVERE: Missing dependency for field: private java.lang.ThreadLocal com.sun.jersey.server.impl.container.servlet.JSPTemplateProcessor.requestInvoker SEVERE: Missing dependency for field: private java.lang.ThreadLocal com.sun.jersey.server.impl.container.servlet.JSPTemplateProcessor.requestInvoker

这是奇怪的原因java.lang.ThreadLocal中仅支持的Andr​​oid 和HttpServletRequest和HttpServletResponse的应该可以,因为我已经包含的servlet-API-2.5.jar libs文件夹中。

This is strange cause java.lang.ThreadLocal is available for Android and HttpServletRequest and HttpServletResponse should be available since I've included servlet-api-2.5.jar in the libs folder.

新泽西依赖于一些使用javax库(JAXB的API-2.2.2.jar,JNDI-1.2.1.jar,STAX-API 1.0-2.jar),我不得不添加到项目,并设置 - -core库参数暂时忽略有关javax包的依赖DEX警告。

Jersey is dependent on some javax libraries (jaxb-api-2.2.2.jar,jndi-1.2.1.jar,stax-api-1.0-2.jar) which I had to add to project and set the --core-library parameter temporary to ignore dex warning about javax packages as dependencies.

我也删除了下面的类(RenderedImageProvider,DataSourceProvider,MimeMultipartProvider从球衣核心jar包com.sun.jersey.core.impl.provider.entity),以避免对java.awt中和javax.mail依赖关系。

I also removed the following classes (RenderedImageProvider,DataSourceProvider,MimeMultipartProvider from package com.sun.jersey.core.impl.provider.entity from jersey core jar) to avoid dependencies on java.awt and javax.mail.

异常跟踪:

javax.servlet.UnavailableException: com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
at org.eclipse.jetty.servlet.ServletHolder.makeUnavailable(ServletHolder.java:409)
at org.eclipse.jetty.servlet.ServletHolder.initServlet(ServletHolder.java:450)
at org.eclipse.jetty.servlet.ServletHolder.getServlet(ServletHolder.java:331)
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:511)
at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:476)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:119)
at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:517)
at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)
at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:935)
at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:404)
at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:184)
at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:870)
at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:117)
at org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:116)
at org.eclipse.jetty.server.Server.handle(Server.java:346)
at org.eclipse.jetty.server.HttpConnection.handleRequest(HttpConnection.java:596)
at org.eclipse.jetty.server.HttpConnection$RequestHandler.headerComplete(HttpConnection.java:1051)
at org.eclipse.jetty.http.HttpParser.parseNext(HttpParser.java:592)
at org.eclipse.jetty.http.HttpParser.parseAvailable(HttpParser.java:214)
at org.eclipse.jetty.server.HttpConnection.handle(HttpConnection.java:426)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint.handle(SelectChannelEndPoint.java:520)
at org.eclipse.jetty.io.nio.SelectChannelEndPoint$1.run(SelectChannelEndPoint.java:40)
at org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:528)
at java.lang.Thread.run(Thread.java:1019)

启动服务器Android的活动:

Start Server Android Activity:

public class StartServerActivity extends Activity {

private Server webServer;

private final static String LOG_TAG = "Jetty";


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);

    setContentView(R.layout.main);

    System.setProperty("java.net.preferIPv4Stack", "true");
    System.setProperty("java.net.preferIPv6Addresses", "false");

    webServer = new Server(8080);

    ServletHolder servletHolder = new ServletHolder(com.sun.jersey.spi.container.servlet.ServletContainer.class);
    servletHolder.setInitParameter("com.sun.jersey.config.property.packages", "com.famenu.server.resources");

    ServletContextHandler servletContextHandler = new ServletContextHandler(webServer, "/api", true, false);
    servletContextHandler.addServlet(servletHolder, "/hello");

    webServer.setHandler(servletContextHandler);


    try {
        webServer.start();
        Log.d(LOG_TAG, "started Web server");

    }
    catch (Exception e) {
        Log.d(LOG_TAG, "unexpected exception starting Web server: " + e);
    }

}

}

球衣资源:

package com.famenu.server.resources;

进口javax.ws.rs.GET; 进口javax.ws.rs.Path; 进口javax.ws.rs.Produces;

import javax.ws.rs.GET; import javax.ws.rs.Path; import javax.ws.rs.Produces;

@Path(/) 公共类HelloResource {

@Path("/") public class HelloResource {

@GET
@Produces("text/plain")
public String getMsg() {

    return "Hello Resource";

}

}

我用码头7.3.0.v20110203,新泽西州1.12,安卓1.6 我来到到这一点后,另一个异常解释<一个href="http://stackoverflow.com/questions/11191346/jersey-on-jetty-on-android-throws-containerexception-no-webapplication-provide">here

I'm using Jetty 7.3.0.v20110203 , Jersey 1.12 , Android 1.6 I arrived till this point after another exception explained here

推荐答案

不使用包/上不支持..平台上的任何其他扫描。

don't use package/any other scanning on .. not supported platforms.

类名属性:com.sun.jersey.config.property.classnames应该为你工作(你需要显式声明所有的根资源(@Pa​​th注解)班)

Classnames property: com.sun.jersey.config.property.classnames should work for you (you need to explicitly declare all your root resource (@Path annotated) classes).

这篇关于泽西岛的码头在Android上抛出ContainerException:本ResourceConfig实例不包含任何根资源类的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆