bbossgroups 组件容器的使用方法浅析
本文重点介绍bbossgroups 中的4大组件容器的特点及使用方法
4大组件容器
[1] ApplicationContext
org.frameworkset.spi.ApplicationContext
包括基本的aop/ioc功能,业务组件、dao组件管理,远程服务,全局属性管理,拦截器,包含声明式事务管理
[2] WebApplicationContextorg.frameworkset.web.servlet.context.WebApplicationContext
管理所有mvc框架中的控制器,包括基本的aop/ioc功能,业务组件、dao组件管理,不提供远程服务(和远程服务协议包无关联)
[3] DefaultApplicationContextorg.frameworkset.spi.DefaultApplicationContext
包括基本的aop/ioc功能,业务组件、dao组件管理,不提供远程服务(和远程服务协议包无关联)
[4] SOAApplicationContext/SOAFileApplicationContext
org.frameworkset.spi.SOAApplicationContext
org.frameworkset.spi.SOAFileApplicationContext
两个轻量级的ioc容器,包含aop/ioc功能、全局属性管理,业务组件、dao组件管理,不包含远程服务、拦截器、不包含声明式事务管理,是DefaultApplicationContext的子类,二者主要用来实现对象xml序列化功能,前者从xml串中反序列化组件,后者从xml文件中反序列化组件
[/list]
4大组件容器的初始化和操作示例
本文涉及的组件配置文件如下:
org/frameworkset/spi/beans/testapplicationcontext.xml
org/frameworkset/soa/datasource-sql.xml
[1] ApplicationContext初始化和使用示例
org.frameworkset.spi.ApplicationContext
初始化:
ApplicationContext context = ApplicationContext.getApplicationContext("org/frameworkset/spi/beans/testapplicationcontext.xml");
RestfulServiceConvertor convertor = context.getTBeanObject("rpc.restful.convertor",RestfulServiceConvertor.class);
RestfulServiceConvertor convertor = (RestfulServiceConvertor)context.getBeanObject("(rmi::172.16.17.216:1099)/rpc.restful.convertor");
<servlet><servlet-name>mvcdispather</servlet-name><servlet-class>org.frameworkset.web.servlet.DispatchServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/bboss-*.xml,/WEB-INF/conf/bboss-*.xml</param-value></init-param><load-on-startup>0</load-on-startup></servlet><servlet-mapping><servlet-name>mvcdispather</servlet-name><url-pattern>*.page</url-pattern></servlet-mapping>
WebApplicationContext context = org.frameworkset.web.servlet.support.WebApplicationContextUtils.getWebApplicationContext();//获取实例//通过以下方式获取mvc容器中的组件实例方法DeskTopMenuShorcutManager m = context.getTBeanObject("deskTopMenuShorcutManager", DeskTopMenuShorcutManager.class);
BaseApplicationContext context = DefaultApplicationContext.getApplicationContext("org/frameworkset/spi/beans/testapplicationcontext.xml"); RestfulServiceConvertor convertor = context.getTBeanObject("rpc.restful.convertor",RestfulServiceConvertor.class);
String content = "<?xml version="1.0" encoding="gbk"?>" +"<esb>"+"<call>"+"<!-- 调度中心需要的数据开始 -->"+"<property name="soamethodcall" " +"class="org.frameworkset.soa.SOAMethodCall" "+"f:requestor="requestor" "+"f:requestid="1000000" "+"f:password="requestpassword" "+"f:encypt="encrypt" "+"f:encyptalgorithem="algorithm" "+"f:serviceid="hilaryserviceid" "+"f:issynchronized="true" >"+"<!-- 调度中心需要的数据结束 -->"+"<!-- 调度中心提交给服务提供方的服务方法信息 -->"+"<property name="soamethodinfo" class="org.frameworkset.soa.SOAMethodInfo" " +"f:methodName="methodname">"+"<property name="paramTypes">"+"<array componentType="Class">"+"<property >String</property>"+"<property >String</property>"+"<property >String[]</property>"+"</array>"+"</property>" +"<property name="params">"+"<array componentType="object">"+"<property name="condition">1=1</property>"+"<property name="orderby">order by ${A}</property>"+"<property>"+"<array componentType="String">"+"<property>A</property>"+"<property>B</property>"+"</array>"+"</property>"+"</array>"+"</property>" +"</property>" +"</property>"+"</call>"+"</esb>";//从xml字符串实例化SOAApplicationContext对象 SOAApplicationContext context = new SOAApplicationContext(content);//获取xml串中包含的组件对象实例SOAMethodCall object = context.getTBeanObject("soamethodcall",SOAMethodCall.class);
SOAFileApplicationContext context = new SOAFileApplicationContext("org/frameworkset/soa/datasource-sql.xml");//获取xml串中包含的组件对象实例SOAMethodCall object = context.getTBeanObject("soamethodcall",SOAMethodCall.class);