bboss ioc容器之间组件引用方法简介

bboss ioc容器之间组件引用方法简介。我们可以在ioc容器直接获取其他容器中的组件,也可以将其他ioc容器中的组件注入到自己的组件中。本文简单说明如何在ioc容器中获取其他ioc容器中定义的组件,其他容器类型可以为:
[b]org.frameworkset.spi.DefaultApplicationContext[/b]
[b]MVC容器[/b]
[b]org.frameworkset.spi.ApplicationContext[/b]

bboss ioc容器参考文章:
[url]http://yin-bp.iteye.com/blog/1153798[/url]

本文涉及到的工厂模式参考文章:
[url]http://yin-bp.iteye.com/blog/1014361[/url]

[size=x-large][b]1.ioc配置文件示例[/b][/size]

<!-- 
本实例说明如何在ioc容器中获取其他ioc容器中定义的组件,其他容器类型包括:
org.frameworkset.spi.DefaultApplicationContext
MVC容器
org.frameworkset.spi.ApplicationContext

bboss ioc容器请参考文章:
http://yin-bp.iteye.com/blog/1153798

涉及到的工厂模式请参考文章:
http://yin-bp.iteye.com/blog/1014361
-->
<properties>
<!--
使用工厂模式,定义一个外部org.frameworkset.spi.ApplicationContext类型的容器对象引用,以便引用容器中的组件
该容器对象通过加载配置文件 org/frameworkset/spi/beans/testapplicationcontext.xml
创建
-->
<property name="test.outnerapplicationcontext"
factory-class="org.frameworkset.spi.ApplicationContext"
factory-method="getApplicationContext">
<construction>
<property value="org/frameworkset/spi/beans/testapplicationcontext.xml"/>
</construction>
</property>

<!--
使用工厂模式定义一个对外部组件的引用组件test_refbean_from_outnerapplicationcontext,
从外部容器test.outnerapplicationcontext中获取名称为rpc.restful.convertor的组件
-->
<property name="test_refbean_from_outnerapplicationcontext"
factory-bean="test.outnerapplicationcontext"
factory-method="getBeanObject">
<construction>
<property value="rpc.restful.convertor"/>
</construction>
</property>


<!--
使用工厂模式,定义bboss MVC类型的容器对象引用,以便引用容器中的组件
该容器对象通过MVC框架自动创建
-->
<property name="test.mvcapplicationcontext"
factory-class="org.frameworkset.web.servlet.support.WebApplicationContextUtils"
factory-method="getWebApplicationContext"/>

<!--
使用工厂模式定义一个对外部组件的引用组件test_refbean_from_mvcapplicationcontext,从MVC容器中获取名称为deskTopMenuShorcutManager的组件
-->
<property name="test_refbean_from_mvcapplicationcontext"
factory-bean="test.mvcapplicationcontext"
factory-method="getBeanObject">
<construction>
<property value="deskTopMenuShorcutManager"/>
</construction>
</property>


<!--
使用工厂模式,定义一个外部org.frameworkset.spi.DefaultApplicationContext 类型的容器对象,以便引用改容器中的组件
该容器对象通过加载配置文件 org/frameworkset/spi/beans/testapplicationcontext.xml
创建
-->
<property name="test.outnerdefaultapplicationcontext"
factory-class="org.frameworkset.spi.DefaultApplicationContext"
factory-method="getApplicationContext">
<construction>
<property value="org/frameworkset/spi/beans/testapplicationcontext.xml"/>
</construction>
</property>

<!--
使用工厂模式定义一个对外部组件的引用组件test_refbean_from_outnerdefaultapplicationcontext,
从外部容器test.outnerdefaultapplicationcontext中获取名称为rpc.restful.convertor的组件
-->
<property name="test_refbean_from_outnerdefaultapplicationcontext"
factory-bean="test.outnerdefaultapplicationcontext"
factory-method="getBeanObject">
<construction>
<property value="rpc.restful.convertor"/>
</construction>
</property>

</properties>


[size=x-large][b]2.ioc配置文件加载和跨ioc容器组件实例获取方法[/b][/size]
我们可以在ioc容器直接获取其他容器的组件,也可以将其他ioc容器的组件注入到自己的组件中,这里值说明第一种情况:
/*
* Copyright 2008 biaoping.yin
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

package org.frameworkset.spi.container;

import org.frameworkset.spi.BaseApplicationContext;
import org.frameworkset.spi.DefaultApplicationContext;
import org.frameworkset.spi.remote.restful.RestfulServiceConvertor;

/**
* <p>Title: IOCReference.java</p>
* <p>Description: </p>
* <p>bboss workgroup</p>
* <p>Copyright (c) 2007</p>
* @Date 2012-8-4 下午2:17:18
* @author biaoping.yin
* @version 1.0
*/
public class IOCReference {

public void test()
{
//初始化ioc容器对象,在该容器对象中定义了三个外部ioc容器组件的引用组件
BaseApplicationContext context = DefaultApplicationContext
.getApplicationContext("org/frameworkset/spi/container/iocreference.xml");
//跨ioc组件实例获取方法示例
RestfulServiceConvertor convertor = context.getTBeanObject("test_refbean_from_outnerapplicationcontext",RestfulServiceConvertor.class);
RestfulServiceConvertor convertor1 = context.getTBeanObject("test_refbean_from_mvcapplicationcontext",RestfulServiceConvertor.class);
RestfulServiceConvertor convertor2 = context.getTBeanObject("test_refbean_from_outnerdefaultapplicationcontext",RestfulServiceConvertor.class);
}
}
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值