Spring事务配置的五种方法Word文档下载推荐.docx
- 文档编号:19703963
- 上传时间:2023-01-09
- 格式:DOCX
- 页数:6
- 大小:68.68KB
Spring事务配置的五种方法Word文档下载推荐.docx
《Spring事务配置的五种方法Word文档下载推荐.docx》由会员分享,可在线阅读,更多相关《Spring事务配置的五种方法Word文档下载推荐.docx(6页珍藏版)》请在冰豆网上搜索。
1.0"
encoding="
UTF-8"
>
beansxmlns="
http:
//www.springframework.org/schema/beans"
xmlns:
xsi="
//www.w3.org/2001/XMLSchema-instance"
context="
//www.springframework.org/schema/context"
aop="
//www.springframework.org/schema/aop"
xsi:
schemaLocation="
//www.springframework.org/schema/beans
//www.springframework.org/schema/beans/spring-beans-2.5.xsdhttp:
//www.springframework.org/schema/contexthttp:
//www.springframework.org/schema/context/spring-context-2.5.xsdhttp:
//www.springframework.org/schema/aophttp:
//www.springframework.org/schema/aop/spring-aop-2.5.xsd"
beans>
beanid="
sessionFactory"
class="
org.springframework.orm.hibernate3.LocalSessionFactoryBean"
propertyname="
configLocation"
value="
classpath:
hibernate.cfg.xml"
/>
configurationClass"
org.hibernate.cfg.AnnotationConfiguration"
/bean>
!
--定义事务管理器(声明式的事务)-->
transactionManager"
org.springframework.orm.hibernate3.HibernateTransactionManager"
ref="
--配置DAO-->
userDaoTarget"
com.bluesky.spring.dao.UserDaoImpl"
userDao"
org.springframework.transaction.interceptor.TransactionProxyFactoryBean"
--配置事务管理器-->
target"
proxyInterfaces"
com.bluesky.spring.dao.GeneratorDao"
<
--配置事务属性-->
transactionAttributes"
props>
propkey="
*"
PROPAGATION_REQUIRED<
/prop>
/props>
/property>
/beans>
第二种方式:
所有Bean共享一个代理基类
transactionBase"
lazy-init="
true"
abstract="
--配置事务属性-->
parent="
第三种方式:
使用拦截器
transactionInterceptor"
org.springframework.transaction.interceptor.TransactionInterceptor"
beanclass="
org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator"
beanNames"
list>
value>
*Dao<
/value>
/list>
interceptorNames"
transactionInterceptor<
第四种方式:
使用tx标签配置的拦截器
tx="
//www.springframework.org/schema/tx"
//www.springframework.org/schema/aop/spring-aop-2.5.xsdhttp:
//www.springframework.org/schema/txhttp:
//www.springframework.org/schema/tx/spring-tx-2.5.xsd"
context:
annotation-config/>
component-scanbase-package="
com.bluesky"
tx:
adviceid="
txAdvice"
transaction-manager="
attributes>
methodname="
propagation="
REQUIRED"
/tx:
advice>
aop:
config>
pointcutid="
interceptorPointCuts"
expression="
execution(*com.bluesky.spring.dao.*.*(..))"
advisoradvice-ref="
pointcut-ref="
/aop:
第五种方式:
全注解
annotation-driventransaction-manager="
此时在DAO上需加上@Transactional注解,如下:
packagecom.bluesky.spring.dao;
importjava.util.List;
importorg.hibernate.SessionFactory;
importorg.springframework.beans.factory.annotation.Autowired;
importorg.springframework.orm.hibernate3.support.HibernateDaoSupport;
importorg.springframework.stereotype.Component;
importcom.bluesky.spring.domain.User;
@Transactional@Component("
)publicclassUserDaoImplextendsHibernateDaoSupportimplementsUserDao{
publicList<
User>
listUsers(){returnthis.getSession().createQuery("
fromUser"
).list();
}
}
- 配套讲稿:
如PPT文件的首页显示word图标,表示该PPT已包含配套word讲稿。双击word图标可打开word文档。
- 特殊限制:
部分文档作品中含有的国旗、国徽等图片,仅作为作品整体效果示例展示,禁止商用。设计者仅对作品中独创性部分享有著作权。
- 关 键 词:
- Spring 事务 配置 方法