首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件架构设计 >

关于spring +hibernate调整的报告!

2012-11-25 
关于spring +hibernate整合的报告!!把hibernate的sessionFactory 交给spring 管理,用xml 配合,交口 UserDA

关于spring +hibernate整合的报告!!
把hibernate  的sessionFactory 交给spring 管理,用xml 配合,

交口 UserDAO,其实现类UserDAOImpl,会调用 SessionFactory,其中的SessionFactory 是用spring 注入(DI) ,起配置xml文档在,beans.xml 如下:

   <bean id="sessionFactory"
class ="com.bjsxt.model.User">   
       <property name="name" value = "chinadengwenly">
       </property>
   </bean>
  
  
    <bean  name = "userdaoImpl" class ="com.bjsxt.dao.impl.UserDAOImpl">
     <property name="sessionFactory" ref ="sessionFactory"></property>
    </bean>
   
    <bean  name = "userservice"  class ="com.bjsxt.service.UserService">
     <property name="userDAO" ref ="userdaoImpl"></property>
    </bean>


这些配置是实现了 一些基本的注入,
值得一提的是测试文档中,

User us = (User)ctx.getBean("User");
service.add(us);
User ur =  new User();
ur.setName("王八蛋金鸡");
service.add(ur);
ctx.destroy();


分别测试了  一个引用beans.xml文档的 注入,和自己new 一个用户的注入

热点排行