用蓝图布线原型 [英] Wiring a prototype in blueprint
问题描述
像Spring一样,蓝图支持原型范围.但是与Spring不同,我看不到任何有关如何使用它的文档.
Like Spring, blueprint supports the prototype scope. But unlike Spring I can't see any documentation about how to use it.
在春季,您可以要求上下文为您提供一个新bean,在蓝图"世界中有什么等效功能?
In Spring you can ask the context to give you a new bean, what's the equivalent in the Blueprint world?
推荐答案
BlueprintContainer.getComponentInstance()确实可以满足您的需求.
BlueprintContainer.getComponentInstance() does exactly what you are looking for.
蓝图容器代表蓝图的托管状态 捆.蓝图容器提供对所有托管对象的访问 成分.这些是bean,服务和服务引用.一种 可以通过注入预定义的容器来获得蓝图容器" "blueprintContainer"组件ID.
A Blueprint Container represents the managed state of a Blueprint bundle. A Blueprint Container provides access to all managed components. These are the beans, services, and service references. A Blueprint Container can be obtained by injecting the predefined "blueprintContainer" component id.
示例
blueprint.xml:
<!-- blueprintContainer is predefined component here -->
<bean id="myService" class="myPackage.MyService">
<property name="container" ref="blueprintContainer"/>
</bean>
<!-- prototype which can be created from myService -->
<bean id="myPrototype" class="myPackage.MyPrototype" scope="prototype"/>
MyService.java:
// ...
// create new instance
MyPrototype myPrototype =
(MyPrototype) container.getComponentInstance("myPrototype");
pom.xml:
<!-- BlueprintContainer from Apache Aries-->
<dependency>
<groupId>org.apache.aries.blueprint</groupId>
<artifactId>org.apache.aries.blueprint.core</artifactId>
<version>1.3.0</version>
</dependency>
这篇关于用蓝图布线原型的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!