Hi, how do I access spring beans using OSGi?
These are the contents of my bundle/ jar file:
This is my MANIFEST.MFCode:sample-si-filter-demo.jar -META-INF/ -spring/ -sample-si-filter-demo.xml -MANIFEST.MF -sample/ -si/ -filter/ -demo/ -Activator.class -ErrorHandler.class -Filter1.class -Filter2.class -Sender.class -Service.class -Tester.class
This is my sample-si-filter-demo.xmlCode:Manifest-Version: 1.0 Created-By: Apache Maven Bundle Plugin Bundle-Activator: sample.si.filter.demo.Activator Import-Package: org.apache.log4j,org.osgi.framework;version="1.3",org. springframework.beans;version="2.5",org.springframework.context;versi on="2.5",org.springframework.context.support;version="2.5",org.spring framework.integration.channel,sample.si.filter.demo Bnd-LastModified: 1290065867965 Export-Package: sample.si.filter.demo;uses:="org.apache.log4j,org.osgi .framework,org.springframework.beans,org.springframework.context,org. springframework.context.support" Bundle-Version: 1.0.0.SNAPSHOT Bundle-Name: Filter Demo Build-Jdk: 1.5.0_13 Bundle-ManifestVersion: 2 Bundle-SymbolicName: com.smart.services.sample-si-filter-demo Tool: Bnd-0.0.357
I want my Activator.java to access the "Sender" bean and call the send method (inside start(BundleContext ctx) method) but I do not know how. I tried to print all the service references using this code:Code:<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:si="http://www.springframework.org/schema/integration" xmlns:file="http://www.springframework.org/schema/integration/file" xmlns:osgi="http://www.springframework.org/schema/osgi" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd http://www.springframework.org/schema/osgi http://www.springframework.org/schema/osgi/spring-osgi-1.2.xsd http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration-1.0.xsd"> <osgi:service id="inboundService" ref="requests" interface="org.springframework.integration.channel.SubscribableChannel"/> <si:gateway id="senderBean" service-interface="sample.si.filter.demo.Sender" default-request-channel="requests"/> <si:publish-subscribe-channel id="requests"/> <si:filter id="filter1" ref="filter1Bean" input-channel="requests" method="filterHelloText" output-channel="filter1Output" discard-channel="discarded"/> <si:channel id="filter1Output"/> <si:service-activator input-channel="filter1Output" ref="serviceBean" method="callService"> </si:service-activator> <si:channel id="discarded"/> <si:service-activator input-channel="discarded" ref="errorBean" method="errorCaught"> </si:service-activator> <bean id="filter1Bean" class="sample.si.filter.demo.Filter1"/> <bean id="serviceBean" class="sample.si.filter.demo.Service"/> <bean id="errorBean" class="sample.si.filter.demo.ErrorHandler"/> </beans>
The output is:Code:public void start(BundleContext ctx) throws Exception { ServiceReference[] srs = ctx.getBundle().getRegisteredServices(); for (ServiceReference reference: srs) { log.info("SVC_REFERENCE: " + reference.toString() + " " + reference.getBundle().getSymbolicName()); } }
As you can see, there was no ApplicationContext or Sender bean that was registered. How do I do that?Code:2010-11-18 16:01:25,331 INFO [Activator] SVC_REFERENCE: [org.osgi.service.packageadmin.PackageAdmin] org.apache.felix.framework 2010-11-18 16:01:25,332 INFO [Activator] SVC_REFERENCE: [] org.apache.felix.framework 2010-11-18 16:01:25,332 INFO [Activator] SVC_REFERENCE: [] org.apache.felix.framework 2010-11-18 16:01:25,332 INFO [Activator] SVC_REFERENCE: [org.osgi.service.startlevel.StartLevel] org.apache.felix.framework
By the way, I am using these bundles:
And I am using Felix as my osgi container.Code:com.springsource.org.aopalliance-1.0.0.jar org.springframework.core-2.5.6.SEC01.jar org.springframework.aop-2.5.6.SEC01.jar org.springframework.integration-1.0.4.RELEASE.jar org.springframework.beans-2.5.6.SEC01.jar org.springframework.transaction-2.5.6.SEC01.jar org.springframework.context-2.5.6.SEC01.jar sample-si-filter-demo-1.0.0-SNAPSHOT.jar
Thanks!


Reply With Quote
