【问题标题】:How to expose the spring couchbase template as OSGI service如何将 spring couchbase 模板公开为 OSGI 服务
【发布时间】:2014-04-11 09:16:27
【问题描述】:

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

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

<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 服务,以便可以在我的其他包中引用该服务。

【问题讨论】:

  • 请提供更多关于您的环境的信息,您使用的是 blueprint 还是 felix scr?还是只有 OSGi?
  • 我们只使用 OSGI。我们有 Apache Karaf OSGI 容器,在 OSGI 之上,我们安装了 spring、cxf、couchbase 等......包。最近发布的couchbase-spring-data有一个叫做模板的概念,想知道如何提供模板作为服务是OSGI,如上所述。
  • 我的回答对你有帮助吗?

标签: osgi spring-data couchbase osgi-bundle spring-data-couchbase


【解决方案1】:

如果您只使用评论中提到的“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 中所有已启动的包以查找上下文文件并自动启动它们。由于 Gemini 蓝图的命名空间支持,您可以在您的上下文中发布或获取服务:

 <osgi:service id="simpleServiceOsgi" ref="simpleService" interface="org.xyz.MyService" />
 <osgi:reference id="messageService" interface="com.xyz.MessageService"/>

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-01-14
    • 1970-01-01
    • 1970-01-01
    • 2014-09-09
    • 2019-03-02
    • 2012-04-25
    相关资源
    最近更新 更多