【发布时间】:2015-10-22 16:24:04
【问题描述】:
配置:
<?xml version="1.0" encoding="UTF-8"?>
<scr:component xmlns:scr="http://www.osgi.org/xmlns/scr/v1.1.0" enabled="true" immediate="true" name="printing">
<implementation class="printing.PrinterManager"/>
<service>
<provide interface="service.printing.IPrinterManager"/>
</service>
</scr:component>
班级:
public class PrinterManager implements IPrinterManager {
public void activate(BundleContext ctx) {
System.err.println("hello");
}
public void deactivate(BundleContext ctx) {
System.err.println("bye");
}
}
当我像这样在代码中的其他地方注入该类的对象时:
@Inject
IPrinterManager pm;
我是否总是得到该类的相同实例? 如果它还不是单例,如何在 osgi/equinox 设施的帮助下使该实例成为单例? (我知道如何用 java/vanilla 方式编写单例,这不是我的问题)
【问题讨论】:
-
@Inject?这不应该是@Reference 吗?
-
我想这取决于您选择的 DI 框架。 @Inject 在 Equinox/e4/javafx 星座中对我有用
标签: osgi equinox declarative-services