1、 . . . . . Spring事务配置的五种方式 Spring配置文件中关于事务配置总是由三个组成局部,分别是DataSource、TransactionManager和代理机制这三局部,无论哪种配置方式,一般变化的只是代理机制这局部。 DataSource、TransactionManager这两局部只是会根据数据访问方式有所变化,比如使用Hibernate进展数据访问 时,DataSource实际为SessionFactory,TransactionManager
2、的实现为 HibernateTransactionManager。
具体如下列图:
根据代理机制的不同,总结了五种Spring事务的配置方式,配置文件如下:
第一种方式:每个Bean都有一个代理
5、/>
8、
13、 lazy-init="true" abstract="true">
14、op>
15、 16、aop=".springframework.org/schema/aop"
xsi:schemaLocation=".springframework.org/schema/beans
.springframework.org/schema/beans/spring-beans-2.5.xsd
.springframework.org/schema/context
.springframework.org/schema/context/spring-context-2.5.xsd
.spri 17、ngframework.org/schema/aop .springframework.org/schema/aop/spring-aop-2.5.xsd">
18、"configurationClass" value="org.hibernate.cfg.AnnotationConfiguration" />
19、/>
20、 21、 22、 class=".bluesky.spring.dao.UserDaoImpl">
23、ns:context=".springframework.org/schema/context"
xmlns:aop=".springframework.org/schema/aop"
xmlns:tx=".springframework.org/schema/tx"
xsi:schemaLocation=".springframework.org/schema/beans
.springframework.org/schema/beans/spring-beans-2.5.xsd
.springframework. 24、org/schema/context
.springframework.org/schema/context/spring-context-2.5.xsd
.springframework.org/schema/aop .springframework.org/schema/aop/spring-aop-2.5.xsd
.springframework.org/schema/tx .springframework.org/schema/tx/spring-tx-2.5.xsd">
25、ation-config />
27、
28、ssion="execution(* .bluesky.spring.dao.*.*(..))" />
29、lns:xsi=".w3.org/2001/XMLSchema-instance"
xmlns:context=".springframework.org/schema/context"
xmlns:aop=".springframework.org/schema/aop"
xmlns:tx=".springframework.org/schema/tx"
xsi:schemaLocation=".springframework.org/schema/beans
.springframework.org/schema/beans/ 30、spring-beans-2.5.xsd
.springframework.org/schema/context
.springframework.org/schema/context/spring-context-2.5.xsd
.springframework.org/schema/aop .springframework.org/schema/aop/spring-aop-2.5.xsd
.springframework.org/schema/tx .springframework.org/s 31、chema/tx/spring-tx-2.5.xsd">
34、rk.beans.factory.annotation.Autowired;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;
import org.springframework.stereotype.Component;
import .bluesky.spring.domain.User;
Transactional
Component("userDao")
public class UserDaoImpl extends HibernateDaoSupport implements UserDao {
public List






