gpt4 book ai didi

jersey - 初始化 Jersey 找不到资源?

转载 作者:行者123 更新时间:2023-12-04 18:04:54 26 4
gpt4 key购买 nike

我已经从 Jersey 1.7 升级到 2.16,但 Jersey 似乎无法找到我的资源(请参阅下面的堆栈)。任何想法发生了什么?我尝试在扩展 ResourceConfig 的自定义应用程序类中初始化,但没有成功


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>

最佳答案

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

方法 1:使用 Application 类

From jersey documentation:

If you extend the Application class to provide the list of relevant root resource classes (getResources()) and singletons (getSingletons()), i.e. your JAX-RS application model, you then need to register it in your web application web.xml deployment descriptor using a Servlet or Servlet filter initialization parameter with a name of javax.ws.rs.Application [sic] as follows

  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 中配置提供者和资源

From jersey documentation:

If there is no configuration properties to be set and deployed application consists only from resources and providers stored in particular packages, you can instruct Jersey to scan these packages and register any found resources and providers automatically:

Example 4.12. Configuring Jersey container Servlet or Filter to use package scanning

<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,因为它也可用于设置其他 Jersey 属性。

如果上述设置不起作用,请提供您的应用程序 pom.xml 和 web.xml。

关于jersey - 初始化 Jersey 找不到资源?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28763747/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com