Felix将OSGI捆绑包列为活动的,但Gogo Shell命令不可访问(与依赖项相关)
此基本代码成功地使命令scopeA:test可在shell中访问:Felix将OSGI捆绑包列为活动的,但Gogo Shell命令不可访问(与依赖项相关),osgi,apache-felix,ipojo,Osgi,Apache Felix,Ipojo,此基本代码成功地使命令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.annotation
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组件的构造函数,那么该命令将不再可访问,并且“help”不会列出它。然而,捆绑包仍然可以加载到活动状态
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 {
}
知道命令不再列出的原因吗?查找有关状态的更多信息的提示,以便我可以更好地调试它?问题是命令需要@Requires位于字段上,而不是构造函数中
@Requires
B b;
构造函数也必须被删除
这是因为gogo有一个调用组件的特殊方法。对我来说,这也需要更改
@ServiceProperty(name = "osgi.command.function", value = "{}")
String[] function = new String[] {
"test"
};
到
B服务实际发布了吗?您可以使用命令
inspect cap service[id]
进行检查,其中[id]应该是包含组件B的捆绑包的id。
@ServiceProperty(name = "osgi.command.function", value = "{test}")
String[] function;