1
此基礎代碼是否能夠成功在使命令scopeA:在shell訪問的測試:菲利克斯列出OSGI包處於活動狀態,但勾勾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組件,它不再可訪問命令,「幫助」不會列出它。然而,該包仍然可以加載到活動狀態。
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的bundle的ID。 –