我有 CDI+OSGI javase 应用程序。CDI-Weld、OSGI-felix 和 pax-cdi。我在“CDI-main”中有以下代码
@ApplicationScoped
public class Foo{
public void postCreate(@Observes ContainerInitialized event, BundleContext ctx) 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());
}
}
当我运行这个应用程序时,我会得到以下输出(尽管我有带有正确驱动程序的打印机!)
$打印服务数量:0
注意,第一个符号是 $;如果我将以下代码添加到捆绑激活器并启动它
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
怎么解释?