按使用配置 OSGI 服务
我想创建一个分页服务,它将根据类似 SQL 的查询返回页面。这是简单的界面:
public interface IPage {
public boolean hasNext();
public Object[] next();
}
当我调用此服务时,我希望能够使用查询字符串和页面大小 int 来初始化它。
如何获取对已使用上面指定的参数初始化的服务的引用?我更喜欢使用声明性服务,但在我看来,如果我想传递参数,我就必须使用 ServiceTracker。
感谢您的帮助。
I want to create a paging service that will return pages based on a SQL like query. Here is the simple interface:
public interface IPage {
public boolean hasNext();
public Object[] next();
}
When I call this service I want to be able to initialize it with a query String and a page size int.
How do I go about getting a reference to the service that has been initialized with the arguments specified above? I would prefer to use declarative services but it seems to me I would have to use ServiceTracker if I wanted to pass in arguments.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以将 IPageFactory 公开为服务,而不是将 IPage 公开为服务。然后,工厂将获取查询和页面大小,并返回初始化的 IPage 实例。
Instead exposing IPage as a service, you might expose an IPageFactory as a service instead. The factory would then take a query and a page size, and return an initialised IPage instance.