在EasyJWeb使用spring容器

<iframe align="center" marginwidth="0" marginheight="0" src="http://www.zealware.com/csdnblog336280.html" frameborder="0" width="336" scrolling="no" height="280"></iframe>
在EasyJWeb里面可以使用spring容器来帮助管理bean:
在JWeb的配置文件中加入:
<bean name="springContainer"></bean>class="org.springframework.context.support.ClassPathXmlApplicationContext">
<constructor-arg type="java.lang.String[]"><br><list><br><value>classpath:applicationContext.xml</value><br></list><br></constructor-arg>
<bean name="innerSpringContainer"></bean>class="com.easyjf.container.impl.SpringContainer">
<property name="factory" ref="springContainer"></property>
其中的<list><value>classpath:dao.xml</value></list>为spring配置文件的路径,
现在暂时使用的是ClassPathXmlApplicationContext。
现在在applicationContext.xml中配置一个bean(片断):
<bean id="queryService"></bean>class="com.easyjf.core.service.impl.QueryServiceImpl">
<property name="dao"><br><bean parent="baseDAO"><br><constructor-arg><br><value>java.lang.Object</value><br></constructor-arg><br></bean><br></property>
然后在Action中:
private IQueryService service;
public void setService(IQueryService service) {
this.service = service;
}
在Action的配置中:
<module name="nesource" path="/nesource" form="" scope="request"></module>...
<page name="edit" url="/cms/newsSourceEdit.html" type="template"></page>
<property name="service" ref="cmsManageService"></property>
...
在配置中用ref指定spring中的bean。
好,
到这里就OK了。
easyJWeb会在框架初始化的时候发现spring容器并初始化,
并从其中加载需要的bean 。
该功能暂定如此,
还会有更多细节的改进。
请继续关注。谢谢!

(注:本文作者, EasyJF开源团队  stef_wu,转载请保留作者声明!)



你可能感兴趣的:(spring容器)