初始化Jersey无法找到资源?

时间:2015-02-27 11:13:06

标签: jersey jersey-2.0

我已经从Jersey 1.7升级到2.16,看起来Jersey无法找到我的资源(见下面的堆栈)。有什么想法会发生什么?我尝试在扩展 ResourceConfig 的自定义Application类中初始化但没有运气


2015-02-27 10:48:58,276  WARN main [AbstractLifeCycle]- FAILED Resources: java.lang.NullPointerException
java.lang.NullPointerException
    at org.glassfish.jersey.server.internal.routing.RuntimeModelBuilder.createInflector(RuntimeModelBuilder.java:128)
    at org.glassfish.jersey.server.internal.routing.RuntimeModelBuilder.createMethodRouter(RuntimeModelBuilder.java:115)
    at org.glassfish.jersey.server.internal.routing.RuntimeModelBuilder.createResourceMethodRouters(RuntimeModelBuilder.java:309)
    at org.glassfish.jersey.server.internal.routing.RuntimeModelBuilder.buildModel(RuntimeModelBuilder.java:173)
    at org.glassfish.jersey.server.internal.routing.Routing$Builder.buildStage(Routing.java:196)
    at org.glassfish.jersey.server.ApplicationHandler.initialize(ApplicationHandler.java:532)
    at org.glassfish.jersey.server.ApplicationHandler.access$500(ApplicationHandler.java:166)
    at org.glassfish.jersey.server.ApplicationHandler$3.run(ApplicationHandler.java:327)
    at org.glassfish.jersey.internal.Errors$2.call(Errors.java:289)
    at org.glassfish.jersey.internal.Errors$2.call(Errors.java:286)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:315)
    at org.glassfish.jersey.internal.Errors.process(Errors.java:297)
    at org.glassfish.jersey.internal.Errors.processWithException(Errors.java:286)
    at org.glassfish.jersey.server.ApplicationHandler.(ApplicationHandler.java:324)
    at org.glassfish.jersey.servlet.WebComponent.(WebComponent.java:336)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:170)
    at org.glassfish.jersey.servlet.ServletContainer.init(ServletContainer.java:388)
    at org.eclipse.jetty.servlet.FilterHolder.doStart(FilterHolder.java:107)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.servlet.ServletHandler.initialize(ServletHandler.java:716)
    at org.eclipse.jetty.servlet.ServletContextHandler.startContext(ServletContextHandler.java:254)
    at org.eclipse.jetty.webapp.WebAppContext.startContext(WebAppContext.java:1238)
    at org.eclipse.jetty.server.handler.ContextHandler.doStart(ContextHandler.java:683)
    at org.eclipse.jetty.webapp.WebAppContext.doStart(WebAppContext.java:480)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at org.eclipse.jetty.server.handler.HandlerWrapper.doStart(HandlerWrapper.java:95)
    at org.eclipse.jetty.server.Server.doStart(Server.java:275)
    at org.eclipse.jetty.util.component.AbstractLifeCycle.start(AbstractLifeCycle.java:64)
    at test.infrastructure.ApplicationHttpServer.start(ApplicationHttpServer.java:50)
    at test.infrastructure.ApplicationHttpServer.start(ApplicationHttpServer.java:33)
    at test.infrastructure.RunJetty.start(RunJetty.java:18)
    at test.infrastructure.RunJetty.main(RunJetty.java:10)

我的web.xml

<filter>
        <filter-name>Resources</filter-name>
        <filter-class>org.glassfish.jersey.servlet.ServletContainer</filter-class>
        <init-param>
            <param-name>org.glassfish.jersey.config.server.provider.packages</param-name>
            <param-value>app.web.rest</param-value>
        </init-param>
</filter>

1 个答案:

答案 0 :(得分:0)

您可以扩展Application类,也可以直接在web.xml中提供提供者和资源列表。

方法1:使用Application类

  

来自球衣文件:

     

如果扩展Application类以提供相关列表   根资源类(getResources())和单例   (getSingletons()),即您的JAX-RS应用程序模型,然后您需要   在Web应用程序web.xml部署描述符中注册它   使用带有名称的Servlet或Servlet过滤器初始化参数   javax.ws.rs.Application [sic]的内容如下

  Example 4.11.  Configuring Jersey container Servlet or Filter to use custom Application subclass      
   <init-param>
        <param-name>javax.ws.rs.Application</param-name>
        <param-value>org.foo.MyApplication</param-value>  
  </init-param>

方法2:web.xml中的提供者和资源配置

  

来自球衣文件:

     

如果没有配置属性   要设置和部署的应用程序仅包含资源和   提供者存储在特定的包中,你可以指示泽西岛   扫描这些包并注册任何找到的资源和提供者   自动:

     

例4.12。配置要使用的Jersey容器Servlet或Filter   包扫描

<init-param>
    <param-name>jersey.config.server.provider.packages</param-name>
    <param-value>
        org.foo.myresources,org.bar.otherresources
    </param-value>
</init-param>
<init-param>
    <param-name>jersey.config.server.provider.scanning.recursive</param-name>
    <param-value>false</param-value>
</init-param>

我的偏好是使用Application,因为它也可用于设置其他球衣属性。

如果上述设置无效,请提供您的应用pom.xml和web.xml。