0

还有一个关于 Spring-data-couchbase 和 OSGI 的问题。

我想根据功能拥有不同的持久性捆绑包,但我想拥有一个通用捆绑包,同时为我提供与沙发库的连接。如果我想从不同的包中扫描存储库,我必须将 template-ref 对象传递给它。

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

模板按照示例如下所示的方式创建

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

基本上,我想知道有没有办法将模板公开为 OSGI 服务,以便可以在我的其他包中引用该服务。

4

1 回答 1

0

如果您只使用评论中提到的“OSGi”,那么您有一个捆绑激活器类来初始化您的上下文。在这种情况下,您的激活器将如下所示:

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 );

   }
}

但是如果你想基于 spring 构建一个 OSGi 应用程序,我建议使用 gemini blueprint 来删除样板代码。Gemini Blueprint 是一个扩展,它扫描 META-INF/spring 中所有已启动的包以查找上下文文件并自动启动它们。由于双子座蓝图的命名空间支持,您可以在您的上下文中发布或获取服务:

 <osgi:service id="simpleServiceOsgi" ref="simpleService" interface="org.xyz.MyService" />
 <osgi:reference id="messageService" interface="com.xyz.MessageService"/>
于 2014-04-14T07:35:52.960 回答