ResourceConfig实例不包含任何根资源类。 (吉斯+泽西+的Jboss)

时间:2015-05-11 14:29:46

标签: java jboss jersey jboss7.x guice-3

我正在尝试将我的rest-app移植到JBoss(JBoss 7上的Guice 3.0 + Jersey 1.19),它就像tomcat 7上的魅力一样,但我在jboss 7上遇到了同样的Resource-Config-Exception :

 Exception starting filter guiceFilter: com.sun.jersey.api.container.ContainerException: The ResourceConfig instance does not contain any root resource classes.
    at com.sun.jersey.server.impl.application.RootResourceUriRules.<init>(RootResourceUriRules.java:99) [jersey-bundle-1.19.jar:1.19]
    at com.sun.jersey.server.impl.application.WebApplicationImpl._initiate(WebApplicationImpl.java:1359) [jersey-bundle-1.19.jar:1.19]
    at com.sun.jersey.server.impl.application.WebApplicationImpl.access$700(WebApplicationImpl.java:180) [jersey-bundle-1.19.jar:1.19]
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:799) [jersey-bundle-1.19.jar:1.19]
    at com.sun.jersey.server.impl.application.WebApplicationImpl$13.f(WebApplicationImpl.java:795) [jersey-bundle-1.19.jar:1.19]
    at com.sun.jersey.spi.inject.Errors.processWithErrors(Errors.java:193) [jersey-bundle-1.19.jar:1.19]
    at com.sun.jersey.server.impl.application.WebApplicationImpl.initiate(WebApplicationImpl.java:795) [jersey-bundle-1.19.jar:1.19]
    at com.sun.jersey.guice.spi.container.servlet.GuiceContainer.initiate(GuiceContainer.java:121) [jersey-guice-1.19.jar:1.19]
    at com.sun.jersey.spi.container.servlet.ServletContainer$InternalWebComponent.initiate(ServletContainer.java:339) [jersey-bundle-1.19.jar:1.19]
    at com.sun.jersey.spi.container.servlet.WebComponent.load(WebComponent.java:605) [jersey-bundle-1.19.jar:1.19]
    at com.sun.jersey.spi.container.servlet.WebComponent.init(WebComponent.java:207) [jersey-bundle-1.19.jar:1.19]
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:394) [jersey-bundle-1.19.jar:1.19]
    at com.sun.jersey.spi.container.servlet.ServletContainer.init(ServletContainer.java:577) [jersey-bundle-1.19.jar:1.19]
    at javax.servlet.GenericServlet.init(GenericServlet.java:242) [jboss-servlet-api_3.0_spec-1.0.0.Final.jar:1.0.0.Final]
    at com.google.inject.servlet.ServletDefinition.init(ServletDefinition.java:117) [guice-servlet-3.0.jar:]
    at com.google.inject.servlet.ManagedServletPipeline.init(ManagedServletPipeline.java:82) [guice-servlet-3.0.jar:]
    at com.google.inject.servlet.ManagedFilterPipeline.initPipeline(ManagedFilterPipeline.java:102) [guice-servlet-3.0.jar:]
    at com.google.inject.servlet.GuiceFilter.init(GuiceFilter.java:172) [guice-servlet-3.0.jar:]
    at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:447) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3269) [jbossweb-7.0.13.Final.jar:]
    at org.apache.catalina.core.StandardContext.start(StandardContext.java:3865) [jbossweb-7.0.13.Final.jar:]
    at org.jboss.as.web.deployment.WebDeploymentService.start(WebDeploymentService.java:90) [jboss-as-web-7.1.1.Final.jar:7.1.1.Final]
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.startService(ServiceControllerImpl.java:1811)
    at org.jboss.msc.service.ServiceControllerImpl$StartTask.run(ServiceControllerImpl.java:1746)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1145) [rt.jar:1.7.0_72]
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:615) [rt.jar:1.7.0_72]
    at java.lang.Thread.run(Thread.java:745) [rt.jar:1.7.0_72]

我的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" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"
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>MyLitteRestService</display-name>

<listener>
  <listener-class>com.restapp.guice.GuiceListener</listener-class>
</listener>
<filter>
    <filter-name>guiceFilter</filter-name>
    <filter-class>com.google.inject.servlet.GuiceFilter</filter-class>
</filter>
<filter-mapping>
    <filter-name>guiceFilter</filter-name>
    <url-pattern>/api/*</url-pattern>
</filter-mapping>

这是guiceListener:

public class GuiceListener extends GuiceServletContextListener {

    @Override
    protected Injector getInjector() {
        return Guice.createInjector(new ServletModule() {
            @Override
            protected void configureServlets() {

                ResourceConfig rc = new PackagesResourceConfig(
                        "com.restapp");
                for (Class<?> resource : rc.getClasses()) {
                    bind(resource);
                }
                serve("/api/*").with(GuiceContainer.class);

            }
        });
    }
}

我尝试了The ResourceConfig instance does not contain any root resource classes中描述的解决方案但似乎没有任何效果。

我在这里做错了什么想法?

0 个答案:

没有答案