【问题标题】:Felix lists OSGI Bundle as Active but Gogo Shell Command Not accessible (dependency related)Felix 将 OSGI Bundle 列为活动但 Gogo Shell 命令不可访问(依赖相关)
【发布时间】:2013-02-07 19:51:35
【问题描述】:

此基本代码成功地使命令 scopeA:test 在 shell 中可访问:

package com.A;

import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.ServiceProperty;
import org.apache.felix.service.command.Descriptor;

@Component(immediate = true)
@Instantiate
@Provides(specifications = Commands.class)
public final class Commands {

    @ServiceProperty(name = "osgi.command.scope", value = "scopeA")
    String scope;

    @ServiceProperty(name = "osgi.command.function", value = "{}")
    String[] function = new String[] {
            "test"
    };

    @Descriptor("Example")
    public void test() {
        System.out.println("hello");
    }
}

但是,如果我添加一个依赖于另一个 OSGI 组件的构造函数,则该命令将不再可访问,并且“帮助”不会列出它。然而,bundle 仍然可以加载到活动状态。

package com.A;

import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Provides;
import org.apache.felix.ipojo.annotations.Requires;
import org.apache.felix.ipojo.annotations.ServiceProperty;
import org.apache.felix.service.command.Descriptor;

import com.B;

@Component(immediate = true)
@Instantiate
@Provides(specifications = Commands.class)
public final class Commands {

    public Commands(@Requires B b) {
    }

    @ServiceProperty(name = "osgi.command.scope", value = "scopeA")
    String scope;

    @ServiceProperty(name = "osgi.command.function", value = "{}")
    String[] function = new String[] {
            "test"
    };

    @Descriptor("Example")
    public void test() {
        System.out.println("hello");
    }
}

B的内容很简单:

import org.apache.felix.ipojo.annotations.Component;
import org.apache.felix.ipojo.annotations.Instantiate;
import org.apache.felix.ipojo.annotations.Provides;

@Component(immediate = true)
@Instantiate
@Provides
final class B {
}

知道为什么不再列出该命令吗?查找有关状态的更多信息以便更好地调试的提示?

【问题讨论】:

  • B服务真的发布了吗?您可以使用命令inspect cap service [id] 进行检查,其中 [id] 应该是包含组件 B 的包的 ID。

标签: osgi apache-felix ipojo


【解决方案1】:

问题是命令需要 @Requires 在字段上而不是在构造函数中。

@Requires
B b;

构造函数也必须被移除。

这是因为 gogo 有一个特殊的方法来调用组件。

【讨论】:

    【解决方案2】:

    对我来说这也需要改变

    @ServiceProperty(name = "osgi.command.function", value = "{}")
    String[] function = new String[] {
        "test"
    };
    

    @ServiceProperty(name = "osgi.command.function", value = "{test}")
    String[] function;
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2020-09-29
      • 2011-09-12
      • 1970-01-01
      • 2019-07-25
      • 2013-01-12
      • 2015-10-05
      • 2016-02-01
      • 2013-02-01
      相关资源
      最近更新 更多