服打工厂 - Bundle消费者返回不同的服务对象
服务工厂 - Bundle消费者返回不同的服务对象public?class?Activator?implements?BundleActivator?{??????S
服务工厂 - Bundle消费者返回不同的服务对象
public?class?Activator?implements?BundleActivator?{??????ServiceRegistration?serviceRegistration;????????????public?void?start(BundleContext?context)?throws?Exception?{??????????//注册服务??????????HelloServiceFactory?helloServiceFactory?=?new?HelloServiceFactory();??????????serviceRegistration?=??context.registerService(HelloService.class.getName(),?helloServiceFactory,?null);????????????????????//获取服务(通过服务工厂取得)??????????ServiceReference?serviceReference?=?context.getServiceReference(HelloService.class.getName());??????????HelloService?selloService?=?(HelloService)context.getService(serviceReference);??????????System.out.println("1:?"?+?selloService.sayHello("cjm"));????????????????????//第二次取得的服务对象与之前取得的是同一个对象??????????serviceReference?=?context.getServiceReference(HelloService.class.getName());??????????selloService?=?(HelloService)context.getService(serviceReference);??????????System.out.println("2:?"?+?selloService.sayHello("cjm"));??????}????????????public?void?stop(BundleContext?context)?throws?Exception?{??????????serviceRegistration.unregister();??????}??}??
?