我无法获得在本地使用服务的蓝图。 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
----
答案 0 :(得分:1)
您不得声明对同一蓝图/包中公开的服务的强制引用。容器变得混乱,因为它想要启动一个服务,引用一个尚未存在的服务(他自己)导致一个不可恢复的GracePeriod。
引用的粗略类比是来自另一个包的Java Import。服务的类比是公共类。 如果要使用其他包中的类,则需要import(= 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>
P.S。如果没有其他捆绑包需要您的LookupMfgService,那么您甚至可以省略 service 声明。