gpt4 book ai didi

java - 使用 Jersey 在 web.xml 中配置提供程序包

转载 作者:行者123 更新时间:2023-11-29 02:58:52 25 4
gpt4 key购买 nike

我正在处理网络服务,但遇到了非常奇怪的错误。这是我的 web.xml 的台词:

<init-param>
<param-name>jersey.config.server.provider.packages</param-name>
<param-value>service</param-value>
</init-param>

据我所知,<param-value>必须引用我的主要应用程序所在的包。但是,我的应用程序在 rest.main包,但 Web 服务仅适用于 service值定义如上。

有什么问题,有人可以向我解释这些行吗?

最佳答案

看看 documentation关于 jersey.config.server.provider.packages配置属性:

Defines one or more packages that contain application-specific resources and providers. If the property is set, the specified packages will be scanned for JAX-RS root resources and providers.

Servlet 2.x 容器

此设置经常在 web.xml 部署描述符中使用,以指示 Jersey 扫描这些包并自动注册任何找到的资源和提供程序:

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

使用此设置,Jersey 将自动发现所选包中的资源和提供程序。默认情况下,Jersey 也会递归扫描子包。

Servlet 3.x 容器

对于 Servlet 3.x 容器,根本不需要 web.xml。相反,一个 @ApplicationPath注释可用于注释自定义 ApplicationResourceConfig为应用程序中配置的所有 JAX-RS 资源创建子类并定义基本应用程序 URI。

使用以下定义将被扫描的包:

@ApplicationPath("resources")
public class MyApplication extends ResourceConfig {

public MyApplication() {
packages("org.foo.myresources,org.bar.otherresources");
}
}

有关更多详细信息,请查看 deployment section Jersey 文件。

重要

  • 始终使用包的限定名称;
  • 在声明多个包时使用;作为分隔符。

关于java - 使用 Jersey 在 web.xml 中配置提供程序包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36473316/

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