【问题标题】:Access to service properties in service consumer ( iPOJO )访问服务使用者 (iPOJO) 中的服务属性
【发布时间】:2013-11-14 15:58:37
【问题描述】:

在 iPOJO 中,有没有办法在服务使用者中读取服务属性(例如 getProperty(key) )? 发布者非常直截了当,但在消费者看来我只能使用过滤器。

谢谢

【问题讨论】:

    标签: osgi ipojo


    【解决方案1】:

    您必须使用回调来检索服务属性:

    @Bind
    public void bindService(HelloService hello, Dictionary<String, Object> properties) {
          // ...
    }
    

    @Bind
    public void bindService(HelloService hello, Map<String, Object> properties) {
      // ...
    }
    

    您甚至可以检索 OSGi 服务注册:

    @Bind
    public void bindService(HelloService hello, ServiceReference<HelloService> reference) {
      // ...
    }
    

    所有详情都在http://felix.apache.org/documentation/subprojects/apache-felix-ipojo/apache-felix-ipojo-userguide/describing-components/service-requirement-handler.html#note-about-callbacks

    【讨论】:

    • 谢谢,这也很酷,我可以检测属性是否已更改:@Modified public void modifiedService(HelloService hello, Map properties) { // ... }
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2014-10-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-07-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多