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 。 该功能暂定如此, 还会有更多细节的改进。 请继续关注。谢谢!
|