0

Had one more question regarding the Spring-data-couchbase and OSGI.

I want to have different persistence bundles based on the functionality but I would like to have a common bundle while provides me the connection to couchbase. If I want to scan for the repositories from a different bundle, I have to pass the template-ref object to it.

<couchbase:repositories base-package="xyz.abc.model"
 couchbase-template-ref="cb-template-first">
</couchbase:repositories>

The template is created in the way as shown below as per the examples

<couchbase:template id="cb-template-first"
     client-ref="cb-first" />

Basically, I wanted to know is there a way to expose the template as an OSGI Service, so that this service can be referenced in my other bundle.

Oliver Drotbohm
  • 80,157
  • 18
  • 225
  • 211
Srikanth Hugar
  • 385
  • 5
  • 22
  • Please provide more information about your environment, are you using blueprint or felix scr? Or just OSGi only? – Martin Baumgartner Apr 11 '14 at 10:32
  • We are using just OSGI. We have Apache Karaf OSGI container, on top of OSGI, we installed spring, cxf, couchbase, etc... bundles. couchbase-spring-data which is release recently has a concept called template, and wanted to know how to provide template as service is OSGI as explained above. – Srikanth Hugar Apr 14 '14 at 06:46

1 Answers1

0

If you use just "OSGi" as mentioned in your comment, you have a bundle activator class which initializes your context. In this case your activator would look like this:

public class Activator implements BundleActivator
{
   @Override
   public void start( BundleContext context ) throws Exception
   {
     // start spring application context 
     // template-interface = application context get bean 
      context.registerService( template-interface.class.getName(), template-interface, null );

   }
}

But if you want to build an OSGi application based on spring i would recommend to use gemini blueprint to remove boilerplate code. Gemini Blueprint is an extensions which scans all started bundles for context-files inside of META-INF/spring and starts them automatically. Due to namespace-support of gemini blueprint, you can publish or fetch a service within your context:

 <osgi:service id="simpleServiceOsgi" ref="simpleService" interface="org.xyz.MyService" />
 <osgi:reference id="messageService" interface="com.xyz.MessageService"/>
Martin Baumgartner
  • 3,524
  • 3
  • 20
  • 31