首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >在blueprint中连接原型

在blueprint中连接原型
EN

Stack Overflow用户
提问于 2013-10-15 23:05:34
回答 2查看 1.6K关注 0票数 2

和Spring一样,blueprint也支持prototype作用域。但与Spring不同的是,我看不到任何关于如何使用它的文档。

在Spring中,你可以询问上下文来给你一个新的bean,在Blueprint世界中有什么等价物呢?

EN

回答 2

Stack Overflow用户

发布于 2013-11-06 10:26:23

BlueprintContainer.getComponentInstance()做的正是您想要的。

osgi documentation:

蓝图容器表示蓝图包的托管状态。Blueprint Container提供对所有托管组件的访问。这些是bean、服务和服务引用。蓝图容器可以通过注入预定义的"blueprintContainer“组件id来获得。

示例

blueprint.xml:

代码语言:javascript
复制
<!-- 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:

代码语言:javascript
复制
// ...
// create new instance
MyPrototype myPrototype = 
     (MyPrototype) container.getComponentInstance("myPrototype");

pom.xml:

代码语言:javascript
复制
<!-- BlueprintContainer from Apache Aries-->
<dependency>
  <groupId>org.apache.aries.blueprint</groupId>
  <artifactId>org.apache.aries.blueprint.core</artifactId>
  <version>1.3.0</version>
</dependency>
票数 4
EN

Stack Overflow用户

发布于 2013-10-16 14:38:31

如果bean的作用域是prototype,那么每次将bean注入到某个地方时,都会创建一个新的bean实例。因此,每个获得prototype注入作用域的bean的客户机都会获得bean的一个新实例。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/19384659

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档