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
それを説明する方法は?