关于spring +hibernate整合的报告!!
把hibernate 的sessionFactory 交给spring 管理,用xml 配合,
交口 UserDAO,其实现类UserDAOImpl,会调用 SessionFactory,其中的SessionFactory 是用spring 注入—I) ,起配置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 一个用户的注入