在EasyJWeb里面可以使用spring容器來幫助管理bean:
?
在JWeb的配置文件中加入:
<bean name="springContainer"
???class="org.springframework.context.support.ClassPathXmlApplicationContext">
???<constructor-arg type="java.lang.String[]">
????<list>
?????<value>classpath:applicationContext.xml</value>
????</list>
???</constructor-arg>
??</bean>
??<bean name="innerSpringContainer"
???class="com.easyjf.container.impl.SpringContainer">
???<property name="factory" ref="springContainer" />
??</bean>
其中的<list><value>classpath:dao.xml</value></list>為spring配置文件的路徑,
現在暫時使用的是ClassPathXmlApplicationContext。
?
現在在applicationContext.xml中配置一個bean(片斷):
?<bean id="queryService"
??class="com.easyjf.core.service.impl.QueryServiceImpl">
??<property name="dao">
???<bean parent="baseDAO">
????<constructor-arg>
?????<value>java.lang.Object</value>
????</constructor-arg>
???</bean>
??</property>
?</bean>
?
然后在Action中:
private IQueryService service;
?public void setService(IQueryService service) {
??this.service = service;
?}
?
在Action的配置中:
<module name="nesource" path="/nesource" form="" scope="request"
???...
???<page name="edit" url="/cms/newsSourceEdit.html" type="template" />
???<property name="service" ref="cmsManageService" />
? ...
??</module>
在配置中用ref指定spring中的bean。
好,
到這里就OK了。
easyJWeb會在框架初始化的時候發現spring容器并初始化,
并從其中加載需要的bean 。
?
?
該功能暫定如此,
還會有更多細節的改進。
posted on 2007-03-20 15:54
簡易java框架 閱讀(1215)
評論(1) 編輯 收藏