我有一个Java类,它作为表示实体的多个其他类的注册表(在我的例子中,各种各样的苹果)。这有两个主要步骤:
<?xml version="1.0" encoding="UTF-8" ?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<bean id="AppleRegistry" class="com.domain.AppleRegistry" activation="lazy" scope="singleton">
<property name="apples">
<set value-type="com.domain.apple.IApple">
<ref component-id="macintosh" />
<ref component-id="baldwin" />
<ref component-id="stayman" />
<ref component-id="crispin" />
</set>
</property>
</bean>
<bean id="macintosh" class="com.domain.apple.IApple"/>
<bean id="baldwin" class="com.domain.apple.IApple"/>
<bean id="stayman" class="com.domain.apple.IApple"/>
<bean id="crispin" class="com.domain.apple.IApple"/>
</blueprint>
<?xml version="1.0" encoding="UTF-8" ?>
<blueprint xmlns="http://www.osgi.org/xmlns/blueprint/v1.0.0"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://www.osgi.org/xmlns/blueprint/v1.0.0 http://www.osgi.org/xmlns/blueprint/v1.0.0/blueprint.xsd">
<bean id="AppleResource" class="com.domain.api.AppleResource" scope="singleton">
<property name="appleRegistry">
<ref component-id="AppleRegistry" />
</property>
</bean>
</blueprint>
我希望我的代码可以工作,但我在日志中遇到错误,包括:
Unable to load com.domain.api.AppleResource from recipe BeanRecipe[name='AppleResource'], trying to load a nested class com.domain.api$AppleResource
我知道我省略了bean实现,但这个问题不是关于它们的。如果相关,我可以根据要求输入一些代码。
由于AppleRegistry和AppleResource都是顶级管理器,因此Blueprint无法自动确定它们之间的依赖关系(如子管理器的隐式依赖关系)。必须明确声明:
depends-on="com.domain.OtherTopLevelManager"
例
<bean id="AppleResource" class="com.domain.api.AppleResource" scope="singleton" depends-on="AppleRegistry">
<property name="appleRegistry">
<ref component-id="AppleRegistry" />
</property>
</bean>