Announcement Announcement Module
Collapse

Spring Dynamic Modules forum decommissioned in favor of Eclipse Gemini Blueprint

With the official first release of Eclipse Gemini Blueprint shipped, the migration of the Spring Dynamic Modules code base to the Eclipse Foundation, as part of the Gemini project, has been completed.

As such, this forum has been decommissioned in favour of the Eclipse Gemini forums.
See more
See less
Is that possible to get osgi service reference without proxy? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Is that possible to get osgi service reference without proxy?

    It's easy to get an OSGi service with following simple configuration:
    <reference id="asyncMessageService" interface="com.xyz.MessageService"/>

    While it always return a proxy to original bean or service exposed by other bundles. I am wondering is that possible to get original instance instead proxy?

    Thanks!

  • #2
    Yes, you can by casting the proxy to a Spring DM interface. See the reference documentation:
    http://static.springsource.org/osgi/...roperty-editor

    and the ImportedOsgiServiceProxy javadoc: http://static.springsource.org/osgi/...viceProxy.html

    Comment


    • #3
      Hi Costin, first thanks for the reply.

      I tried following configuration:
      Code:
      <reference id="myService" interface="com.xyz.MyServiceInterface"/>
      		
      <bean id="serviceConsumer" class="MyServiceConsumerImpl">
        <property name="serviceReferenceField" ref="myService"/>                                      
        <property name="myServiceFiled" ref="myService"/>                                               
      </bean>
      I have com.xyz.MyServiceImpl bean exported as OSGi service from other bundle.

      My goal is to get the com.xyz.MyServiceImpl bean injected to serviceConsumer as myServiceFiled. Not the proxy created by Spring DM. I am not interested to get the raw ServiceReference.

      I don't like proxy for the service like cache interface, which could be invoked thousands times per second.

      Apologize if didn't make it clear at first place.

      However, I could get the raw service object by following code:
      Code:
      ServiceReference nativeReference = ((ServiceReferenceProxy)serviceReference).getTargetServiceReference();
      com.xyz.MyServiceImpl myServiceImpl= (com.xyz.MyServiceImpl)bundleContext.getService(nativeReference);
      I want to know is it possible to inject com.xyz.MyServiceImpl raw instance by configuration instead of my code. Or it could be a feature for future.

      Cheers!

      Comment

      Working...
      X