Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/spring/12.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
结合OSGi蓝图和spring配置_Spring_Osgi_Spring Dm_Blueprint Osgi - Fatal编程技术网

结合OSGi蓝图和spring配置

结合OSGi蓝图和spring配置,spring,osgi,spring-dm,blueprint-osgi,Spring,Osgi,Spring Dm,Blueprint Osgi,关于Spring配置和OSGi蓝图(例如Gemini蓝图)的结合,有什么好的/最佳的实践吗?您使用哪些XML文件?您将它们放在您的OSGi捆绑包中的什么位置(META-INF/spring,OSGi-INF)?以下哪种实践将允许您结合Blueprint的非Gemini实现重用捆绑包 背景:我们正在从Spring/Spring DM转换到Spring/Blueprint。我知道Blueprint定义了元素。然而,我们偶尔会遇到这样的情况:Blueprint规范有限的bean定义功能不能满足我们的所

关于Spring配置和OSGi蓝图(例如Gemini蓝图)的结合,有什么好的/最佳的实践吗?您使用哪些XML文件?您将它们放在您的OSGi捆绑包中的什么位置(
META-INF/spring
OSGi-INF
)?以下哪种实践将允许您结合Blueprint的非Gemini实现重用捆绑包


背景:我们正在从Spring/Spring DM转换到Spring/Blueprint。我知道Blueprint定义了
元素。然而,我们偶尔会遇到这样的情况:Blueprint规范有限的bean定义功能不能满足我们的所有需求。因此,在我们的捆绑包和Blueprint中通过OSGi服务使用Spring配置似乎是一个不错的选择。

Blueprint文件应该放在OSGi-INF/Blueprint/下,并命名为*.xml(通常是Blueprint.xml)。该位置符合OSGi4.2蓝图规范,将与白羊座或双子座合作

SpringDM文件(您可能知道)位于META-INF/Spring/下,并且也被命名为*.xml(通常是beans.xml)

这两个文件应该能够和平共存。不过,只有在您对每个安装的容器都有支持的情况下,它们才会起作用

布线应通过OSGi服务注册表完成

至于迁移,我们一直使用SpringDM来实现我们在Blueprint中无法实现的功能。其他一切都已迁移到Blueprint

您使用哪些XML文件?你把它们放在你的OSGi包里的什么地方 (META-INF/spring,OSGi-INF)?以下哪种做法允许您 将bundle与非Gemini实现结合使用 蓝图

Gemini Blueprint同等对待这两个目录,但OSGI-INF/Blueprint/*.xml是通用OSGI Blueprint规范中唯一指定的目录。

建议的做法是:

[…]A 建议的做法是拆分应用程序上下文配置 到至少两个文件中,以约定modulename-context.xml命名 和modulename-osgi-context.xml。modulename-context.xml文件 包含独立于任何 奥斯基。modulename-osgi-context.xml文件包含bean 用于导入和导出OSGi服务的定义。可能是(但不是) 不需要)使用Gemini Blueprint OSGi模式作为顶层 名称空间而不是Spring“bean”名称空间

我试过这个,效果很好。我将Gemini Blueprint用于我的一个项目,其中包含文件
META-INF/spring/context.xml
,该文件定义了我的bean及其关系,以及
META-INF/spring/osgi-context.xml
,该文件定义了从osgi服务公开/导入哪些bean以及如何公开
context.xml
看起来像

<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <bean id="myOrdinarySpringBean" class="com.acme.impl.Foo"/>
</beans>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
    <service id="myOsgiService" ref="myOrdinarySpringBean" interface="com.acme.Foo"/>
</blueprint>
当然,您也可以在这里使用
名称空间和根元素,但必须定义
xmlns:osgi
并在服务前面加上前缀:
,这样才能工作。在我的情况下,我不需要双子座特定的蓝图的东西,所以我对这个通用的蓝图配置很满意。同样,我也可以在
context.xml
中使用
名称空间,但是这个特定的应用程序是一个被移植到OSGi的旧应用程序,所以我现在更喜欢保持特定于Spring的配置

另一个应用程序也有自己的
osgicontext.xml
类似

<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">
  <reference id="myOrdinarySpringBeanImportedFromOsgi" interface="com.acme.Foo" availability="mandatory"/>
</blueprint>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
    <bean id="myOrdinaryOtherSpringBean" class="com.acme.impl.Bar">
        <property name="foo" ref="myOrdinarySpringBeanImportedFromOsgi"/>
    </bean>
</beans>
而且根本不关心myOrdinarySpringBeanImportedFromOsgi是从OSGi服务导入还是定义为同一应用程序上下文中的普通SpringBean


这些
META-INF/osgi context.xml
配置可以简单地移动到
osgi-INF/blueprint/
,如果我想让自己与双子座蓝图实现脱钩,但目前我更喜欢将这两部分放在同一个位置,以避免目录结构混乱。

我认为它在JBoss Fuse中不起作用。在Spring DM xml中无法识别Aries OSGi xml中导入的服务。我认为您不能公开和使用同一捆绑包中的服务。这不是blueprint/spring互操作性问题。同样的问题也会发生在spring或blueprint上。@mjmeno是否必须为spring应用程序上下文定义基于xml的配置,或者基于注释的配置也可以?@jayantmishra我不确定,我不知道在我参与的项目上做过什么。返回了一些搜索,这意味着它可能是可能的。@mjmeno感谢指针,将尝试它n let you knwhi@eml Lundberg定义spring应用程序时必须使用基于xml的配置吗context@jayantmishra很抱歉我不知道——自从我5年前写这篇文章以来,我还没有真正接触过Spring或OSGi。这是一个很好的答案,我非常感谢你提出了一个非常好的问题