将Jersey服务实例发布到Grizzly [英] Publishing Jersey service instance to Grizzly

查看:117
本文介绍了将Jersey服务实例发布到Grizzly的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

通过执行以下操作,我可以将球衣服务发布到灰熊

I can publish a jersey service to grizzly by doing the following

final String baseUri = "http://localhost:51000";
final Map<String, String> initParams = new HashMap<String, String>();
initParams.put("com.sun.jersey.config.property.packages", "my.rest.service");
SelectorThread threadSelector = GrizzlyWebContainerFactory.create(baseUri, initParams);

因此将扫描指定的程序包以查找带有@Path注释的任何服务类,并将它们初始化.我的问题是,有没有办法指定预初始化的球衣服务类-通过自定义工厂初始化,甚至只是通过执行新的MyService()-并将其发布到Grizzly或任何其他容器?

So the specified package will be scanned for any service classes annotated with @Path, and they will be initialized. My question is, is there any way to specify a pre-initialized jersey service class - initialied via a custom factory or even just by doing new MyService() - and publish it to Grizzly or any other container?

推荐答案

您可以使用GrizzlyServerFactory.create(URI u,ResourceConfig rc)并将您的单例添加到提供的ResourceConfig中.即:

You can use GrizzlyServerFactory.create(URI u, ResourceConfig rc) and add your singletons to provided ResourceConfig. ie:

final String baseUri = "http://localhost:51000";
final ResourceConfig rc = new PackagesResourceConfig("my.rest.service");
rc.getSingletons().add(new MyInstantiatedResource());
SelectorThread threadSelector = GrizzlyServerFactory.create(baseUri, rc);

这篇关于将Jersey服务实例发布到Grizzly的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆