蓝图强制依赖到强制依赖

Blueprint mandatory dependancy to mandatory dependency

请帮我解决一个问题。我有一个 osgi 包。蓝图配置如下所示

<?xml version="1.0" encoding="UTF-8"?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0">

    <bean class="test.SomeBean">
        <argument>
            <reference-list availability="mandatory" member-type="service-object" interface="test.Service1"/>
        </argument>
    </bean>

    <service interface="test.Service1">
        <bean class="test.Service1Impl">
            <argument>
                <reference-list availability="mandatory" member-type="service-object" interface="test.Service2"/>
            </argument>
        </bean>
    </service>

    <service interface="test.Service2">
        <bean class="test.Service2Impl"/>
    </service>

</blueprint>

部署后我得到 java.util.concurrent.TimeoutException。如果我将 Service2 声明移动到另一个包或将可用性更改为可选,则一切正常。为什么?

原因是您依赖于您也提供的服务。 BLueprint 无法为强制服务执行此操作。

原因是每当蓝图遇到强制引用时,它都会确保在开始之前解决依赖关系。只有当所有强制引用都被解决时,上下文的服务才会被发布。