打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
在EasyJWeb使用spring容器
userphoto

2007.03.21

关注
在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 。
本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
Spring Security(3.1.7) CAS Authentication
Spring常用的三种注入方式
【第三章】 DI 之 3.1 DI的配置使用 ——跟我学spring3
和喜欢Spring的工程师谈谈Spring Beans 自动装配
Spring中Bean的命名问题(id和name区别)及ref和idref之间的区别
spring依赖注入
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服