Java OSGI+;CDI:系统打印机检测到的奇怪行为
我有CDI+OSGiJavaSE应用程序。CDI焊接、OSGI felix和pax CDI。我在“CDI main”中有以下代码 当我运行此应用程序时,我将获得以下输出(尽管我有带正确驱动程序的打印机!) $打印服务数量:0 注意,第一个符号是$; 如果我向bundle activator添加以下代码并启动它Java OSGI+;CDI:系统打印机检测到的奇怪行为,java,osgi,cdi,weld,pax,Java,Osgi,Cdi,Weld,Pax,我有CDI+OSGiJavaSE应用程序。CDI焊接、OSGI felix和pax CDI。我在“CDI main”中有以下代码 当我运行此应用程序时,我将获得以下输出(尽管我有带正确驱动程序的打印机!) $打印服务数量:0 注意,第一个符号是$; 如果我向bundle activator添加以下代码并启动它 public class Activator implements BundleActivator { public void start(BundleContext conte
public class Activator implements BundleActivator {
public void start(BundleContext context) throws Exception {
PrintService[] printServices = PrintServiceLookup.lookupPrintServices(null, null);
System.out.println("#Number of print services: " + printServices.length);
for (PrintService printer : printServices)
System.out.println("#Printer: " + printer.getName());
}
public void stop(BundleContext context) throws Exception {
}
}
请注意,第一个符号是#。然后检测到我的所有打印机:
#Number of print services: 1
#Printer: MF3110
Jun 14, 2015 1:47:34 PM org.jboss.weld.bootstrap.WeldStartup startContainer...
....
$Number of print services: 1
$Printer: MF3110
如何解释?PrintServiceLookup是在单独的捆绑包中定义的,还是使用来自单独OSGI服务的代码?它可能与osgi服务基数有关吗?在第一个代码段中,
PrintServiceLookup.lookupPrintServices
是在与第二个代码段不同的生命周期阶段调用的
在第一个示例中,当调用lookupPrintServices
时,容器或扩展器可能没有满足PrintServiceLookup
的所有依赖项
在第二个示例中,这些依赖关系可能会得到满足,因为在Bundle Activator的start
方法中调用了lookupPrintServices
,该方法在启动阶段由容器调用。在开始阶段,容器已经解析了捆绑包的所有依赖项
希望我能帮上忙。可能是因为任意开始订购。#vs$字符显然没有关联,这纯粹是巧合。
#Number of print services: 1
#Printer: MF3110
Jun 14, 2015 1:47:34 PM org.jboss.weld.bootstrap.WeldStartup startContainer...
....
$Number of print services: 1
$Printer: MF3110