Importing a OSGi service that is a singleton bean (that has a factory method) -
how import exported osgi service that's singleton bean?
i end getting exception follows:
unable start blueprint container bundle opaclient org.osgi.service.blueprint.container.componentdefinitionexception: unable find matching constructor on class com.opa.gateway.opagateway arguments [] when instantiating bean opagateway @ org.apache.aries.blueprint.container.beanrecipe.getinstance(beanrecipe.java:336)
my blueprint xml service exported follows:
<bean id="opagateway" class="com.opa.gateway.opagateway" factory-method="getinstance"/> <service ref="opagateway" interface="com.opa.gateway.iopagateway" />
and service referenced in bundle follows:
<reference interface="com.opa.gateway.opagateway" component-name="opagateway" availability="mandatory" />
is there way directly reference singleton bean that's osgi service?
yes, can reference singleton osgi service. make sure (as @balazs suggested) class has static function/method getinstance()
no arguments.
have @ blueprint below. hope gives clue... (if need complete sample can try post it.
<bean id="opagateway" class="org.test.opagateway" factory-method="getinstance"> </bean> <bean id="opaclient" class="org.test.client.opaclient" init-method="startup" destroy-method="shutdown"> </bean> <service ref="opagateway" interface="org.test.iopagateway" /> <reference interface="org.test.iopagateway" availability="optional"> <reference-listener bind-method="setopagateway" unbind-method="unsetopagateway"> <ref component-id="opaclient"/> </reference-listener> </reference>
bean opagateway (org.test.opagateway). class implementing
org.test.iopagateway
. instantiated static methodgetinstance()
:public class opagateway implements iopagateway { private static opagateway instance = null; public static opagateway getinstance () { if(instance == null) { instance = new opagateway(); } return instance; } // simple method... @override public string printmessage() { return "i opagateway"; } }
bean: opaclient: consumer or class references opagateway:
public class opaclient { public void setopagateway(iopagateway c) { if(c != null) { system.out.println("message: " + c.printmessage()); } } public void unsetopagateway(iopagateway c) { } }
the reference-listener: injects instance of
opagateway
inopaclient
using bind/unbind-method.
you can find more information here: http://www.ibm.com/developerworks/library/os-osgiblueprint/
Comments
Post a Comment