osgi: Using ServiceFactories?

后端 未结 3 1381
暖寄归人
暖寄归人 2020-12-09 22:05

I\'m currently trying to get a simple bundle containing a Service Factory running.

This is my factory class:

public class SvcFactory implements Servi         


        
3条回答
  •  时光取名叫无心
    2020-12-09 22:35

    ServiceFactory allows your code to provide customized service object for different bundles. Note that with ServiceFactory, clients of your service still do not control when new instance is created, they lookup service by its interface (ServiceB) as usual. So, for them, there is no difference if your service is registered as ServiceFactory or not.

    With declarative services, you should not implement ServiceFactory yourself. Just add servicefactory="true" attribute to the element (you already did) and different instances of your component class will be created (activated) automatically for different requesting bundles. You need to specify ServiceBImpl as an implementation class of the component.

提交回复
热议问题