【问题标题】:using a Java blueprint service defintion使用 Java 蓝图服务定义
【发布时间】:2016-08-07 21:18:10
【问题描述】:

我无法获得正确使用本地服务的蓝图。 OSGi 服务器 (karaf) 显示 GracePeriod 并最终在 ILookupMfgService 上等待超时。

如果我删除参考线,捆绑包开始并有一个ILookupMfgService 可用。

对我做错了什么有什么建议吗?

感谢您帮助我学习!

提摩太

<blueprint default-activation="eager" xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:jpa="http://aries.apache.org/xmlns/jpa/v1.0.0" xmlns:tx="http://aries.apache.org/xmlns/transactions/v1.0.0" xmlns:cm="http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0"

    xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0 
            http://www.w3.org/2001/XMLSchema-instance http://www.w3.org/2001/XMLSchema-instance 
            http://aries.apache.org/xmlns/jpa/v1.0.0 http://aries.apache.org/xmlns/jpa/v1.0.0 
            http://aries.apache.org/xmlns/transactions/v1.0.0 http://aries.apache.org/xmlns/transactions/v1.0.0
            http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 http://aries.apache.org/blueprint/xmlns/blueprint-cm/v1.1.0 ">

<!-- implemenation of the service -->
    <bean id="lookupMfgServiceStubImpl" class="com.services.jpa.LookupMfgServiceStub" scope="singleton"
        init-method="init" />

<!-- create a service with the implementation -->
    <service id="lookupMfgServiceStubLocal" ref="lookupMfgServiceStubImpl" interface="com.services.ILookupMfgService" />

<!-- create a reference for injecting into another bean - this line causes the GracePeriod / timeout --> 
    <reference id="lookupMfgServiceStubRef" interface="com.services.ILookupMfgService" availability="mandatory" ctivation="eager" />

    <bean id="EntityImpl" class="com.services.jpa.Entity" scope="singleton" init-method="init">
<!-- use the service - won't work without the reference above being valid -->
        <property name="lookupMfg" ref="lookupMfgServiceRef" />      
    </bean>
 </blueprint>

没有参考线

karaf@root()> services -p 123

com.server.services (123) provides:
----------------------------------------
objectClass = [com.services.ILookupMfgService]
osgi.service.blueprint.compname = lookupMfgServiceStubImpl
service.id = 932
----

【问题讨论】:

    标签: java karaf blueprint


    【解决方案1】:

    您不得声明对同一蓝图/捆绑中公开的服务的强制引用。容器会感到困惑,因为它想要启动一个引用尚未存在的服务(他自己)的服务,这会导致无法恢复的 GracePeriod。

    引用的粗略类比是从另一个包导入的Java。服务的类比是公共类。 如果您想使用来自不同包的类,则需要导入 (=reference)。

    在您的示例中,您不需要参考,因为您在捆绑包中。您可以直接引用您声明的 Bean:

    <!-- implemenation of the service -->
    <bean id="lookupMfgServiceStubImpl" class="com.services.jpa.LookupMfgServiceStub" scope="singleton"
        init-method="init" />
    
    <!-- create a service with the implementation -->
    <service id="lookupMfgServiceStubLocal" ref="lookupMfgServiceStubImpl" interface="com.services.ILookupMfgService" />
    
    <bean id="EntityImpl" class="com.services.jpa.Entity" scope="singleton" init-method="init">
    <!-- use the service - won't work without the reference above being valid -->
        <property name="lookupMfg" ref="lookupMfgServiceStubImpl" />      
    </bean>
    

    附言如果没有其他捆绑包需要您的 LookupMfgService,那么您甚至可以省略 service 声明。

    【讨论】:

      猜你喜欢
      • 2013-06-05
      • 2021-03-20
      • 1970-01-01
      • 1970-01-01
      • 2016-02-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-27
      相关资源
      最近更新 更多