使用 web.xml 配置 Grizzly
我可以使用以下几行启动 grizzly 并在其上部署 Jersey Web 服务。
protected HttpServer create() throws Throwable {
ResourceConfig rc = new PackagesResourceConfig("com.resource", "com.provider");
HttpServer server = GrizzlyServerFactory.createHttpServer(uri, rc);
return server;
}
但是有没有办法加载 web.xml
而不是 ResourceConfig
?
<web-app>
<servlet>
<servlet-name>Jersey</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.resource, com.provider</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
I can start grizzly and deploy Jersey webservices on it with the following lines.
protected HttpServer create() throws Throwable {
ResourceConfig rc = new PackagesResourceConfig("com.resource", "com.provider");
HttpServer server = GrizzlyServerFactory.createHttpServer(uri, rc);
return server;
}
But is there a way to load a web.xml
instead of a ResourceConfig
?
<web-app>
<servlet>
<servlet-name>Jersey</servlet-name>
<servlet-class>com.sun.jersey.spi.container.servlet.ServletContainer</servlet-class>
<init-param>
<param-name>com.sun.jersey.config.property.packages</param-name>
<param-value>com.resource, com.provider</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Jersey</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
</web-app>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
目前似乎没有直接的方法可以使用
web.xml
配置 grizzly。不过,我使用了部分解决方案,这可能是一个开始。web.xml
首先要了解解决方案,我们必须了解使用
web.xml
的含义是什么。它基本上用于配置您的 Web 应用程序(有关更多详细信息,请参阅此答案)。在本例中,我们正在为 servlet 配置init-params
。(部分)解决方案
我们可以使用 Grizzly 作为 servlet 并初始化参数,而不是使用
web.xml
和ResouceConfig.class
。例如,
会给出如下内容:
有了这个,我们就可以放置我们想要的所有
init-params
。但是,此解决方案无法替换整个
web.xml
。It seems that there is currently no direct way to configure grizzly with a
web.xml
. However I have used a partial solution that may be a beginning.web.xml
First to understand the solution, we must understand what is the meaning of using a
web.xml
. It is basically use for configure your web application (see this answer for a more detail). In this case we are configuringinit-params
for the servlet.The (partial) solution
Instead of using the
web.xml
and instead of usingResouceConfig.class
, we can use Grizzly as our servlet and initializing the parameters.For example
would give something like :
With this, we can therefore put all the
init-params
that we want to.However this solution cannot replace a whole
web.xml
.