Spring整合hibernate中Datasouce、SessionFactory、Transaction配置
来源:互联网 发布:多重快速选择算法 编辑:程序博客网 时间:2024/05/28 18:43
<?xml version="1.0" encoding="UTF-8"?><beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:aop="http://www.springframework.org/schema/aop" xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.5.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-2.5.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-2.5.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-2.5.xsd"><context:annotation-config /><context:component-scan base-package="com.bjsxt" /><aop:aspectj-autoproxy />
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close"> <property name="driverClassName" value="${jdbc.driverClassName}"/> <property name="url" value="${jdbc.url}"/> <property name="username" value="${jdbc.username}"/> <property name="password" value="${jdbc.password}"/></bean><context:property-placeholder location="jdbc.properties"/> <bean id="sessionFactory" class="org.springframework.orm.hibernate3.annotation.AnnotationSessionFactoryBean"> <property name="dataSource" ref="dataSource"/> <property name="annotatedClasses"> <list> <value>com.bjsxt.model.People</value> </list> </property> <property name="hibernateProperties"> <props> <prop key="hibernata.dialect">org.hibernate.dialect.MySQLDialect</prop> <prop key="hibernate.show_sql">true</prop> </props> </property> </bean> <tx:annotation-driven transaction-manager="txManager"/> <bean id="txManager" class="org.springframework.orm.hibernate3.HibernateTransactionManager"> <property name="sessionFactory" ref="sessionFactory"/> </bean></beans>
在service层直接在方法中配置:
@Transactionalpublic void add(People people) {userDAO.save(people);}
使用xml替换@Transactional:
<aop:config><aop:pointcut id="productServiceMethods"expression="execution(* com.bjsxt.service..*.*(..))" /><aop:advisor advice-ref="txAdvice" pointcut-ref="productServiceMethods" /></aop:config><tx:advice id="txAdvice" transaction-manager="txManager"><tx:attributes><tx:method name="add*" propagation="REQUIRED" /><tx:method name="modify*" propagation="REQUIRED" /></tx:attributes></tx:advice>
0 0
- Spring整合hibernate中Datasouce、SessionFactory、Transaction配置
- Spring3与Hibernate4整合,Spring中配置Hibernate基于XML和annotation的sessionFactory方式。
- spring与hibernate整合applicatContext.xml配置,得到sessionFactory
- SSH整合中 hibernate托管给Spring得到SessionFactory
- SSH整合中 hibernate托管给Spring得到SessionFactory
- Hibernate中SessionFactory配置
- Hibernate中SessionFactory配置
- Hibernate中SessionFactory配置
- Hibernate的Transaction SessionFactory
- spring hibernate整合时SessionFactory为空
- spring集成hibernate applicationContext.xml文件中SessionFactory配置
- 转载: Hibernate中SessionFactory配置
- Spring与Hibernate整合中,使用OpenSessionInViewFilter后出现sessionFactory未注入问题
- 在Spring整合Hibernate的框架中,HibernateTemplate、SessionFactory和Session之间是怎样的关系?
- Spring整合的Hibernate的框架中,HibernateTemplate、SessionFactory和Session之间的关系
- spring整合hibernate中sessionFactory的两种常用引入方式
- Spring中注入Hibernate的SessionFactory
- Spring+Hibernate 整合配置
- java_easyui体系之DataGrid(5)
- HTML5 2D游戏引擎研发系列 第六章 <Canvas技术篇-画布技术-混色特效和粒子>
- splash 启动界面
- Asp.net MVC DropDownLists 几篇非常好的博文
- IOS tableView 点击一下cell,效果随离开触摸恢复(个人)
- Spring整合hibernate中Datasouce、SessionFactory、Transaction配置
- OSTCBX/Y OSTCBBitX/Y 在TCB结构里的作用
- 云计算 安全
- 关于Spring管理Hibernate的批量数据处理
- w3cschool菜鸟教程开通移动版本
- ffmpeg基础学习
- Linux初始root密码设置
- MySql模糊查询like通配符使用详细介绍
- 关于ie6、ie7折行问题(li用了float)