I have a Java class that serves as a registry of multiple other classes that represent entities (in my example, varieties of apples). There are two major steps to this:
The entities get defined in blueprintA. The registry also gets populated in blueprintA. My understanding is that blueprint automatically handles the right order as part its dependency injection process (and across blueprint.xml files).
A resource class gets created and has the registry injected either as an argument of the constructor or as an argument to a property setter. In my case, I used a bean setter.
<?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>
I would expect my code to work, but I am getting errors in the log, including:
Unable to load com.domain.api.AppleResource from recipe BeanRecipe[name='AppleResource'], trying to load a nested class com.domain.api$AppleResource
I am aware that I left out the bean implementations, but this question is not about them. I could type up some code upon request, should those be relevant.
Because both AppleRegistry and AppleResource are top-level managers, Blueprint cannot automatically determine the dependency between them (like implicit dependencies of submanagers). It must be explicitly declared:
depends-on="com.domain.OtherTopLevelManager"
Example
<bean id="AppleResource" class="com.domain.api.AppleResource" scope="singleton" depends-on="AppleRegistry">
<property name="appleRegistry">
<ref component-id="AppleRegistry" />
</property>
</bean>