ManagedServiceFactory的注册如下: -
private ServiceRegistration factoryService;
public void start(BundleContext context) {
Dictionary props = new Hashtable();
props.put("service.pid", "test.smssenderfactory");
factoryService = context.registerService(ManagedServiceFactory.class.getName(),
new SmsSenderFactory(), props);
}
如何在蓝图中做到这一点(示例示例非常有用)?
答案 0 :(得分:0)
Apache aries支持托管服务。您可以在https://svn.apache.org/repos/asf/aries/trunk/blueprint/blueprint-itests/src/test/resources/ManagedServiceFactoryTest.xml的Apache Aries蓝图的集成测试中找到示例。在这种情况下,可以更改SMSSenderFactory的代码,而不是直接实现ManagedServiceFactory,因为蓝图会为您执行此操作。
如果那是你的问题,你也可以将代码(你在问题中作为样本提供)嵌入到bean的init方法中。在这种情况下,ManagedServiceFactory应该在bean的destroy方法中取消注册。
第三种选择是将蓝图排除在游戏之外。您已经有了ManagedServiceFactory实现,为什么不在Bundle的Activator中注册它呢?
第四个选项是将Declarative Services与其中一个注释集一起使用。在这种情况下,还将生成元类型信息,您可以通过Web控制台配置SMSSender。
我建议你使用最后一个选项。