-
事務(wù)傳播行為(七種)查看全部
-
TransactionDefinition 事務(wù)的隔離級別查看全部
-
事務(wù)管理器PlatformTransactionManager接口下面的相關(guān)實現(xiàn)類查看全部
-
spring事務(wù)管理接口查看全部
-
事務(wù)的 ACID 事務(wù)具有四個特征:原子性( Atomicity )、一致性( Consistency )、隔離性( Isolation )和持續(xù)性( Durability ) 原子性、一致性、隔離性、持久性。 原子性 事務(wù)是不可分割的工作單位,事務(wù)中的操作要么都發(fā)生,要么都不發(fā)生. 一致性 事務(wù)前后數(shù)據(jù)的完整性必須保持一致. 隔離性 多用戶并發(fā)訪問數(shù)據(jù)庫時,一個用戶的事務(wù)不能被其他用戶的事務(wù)所干擾,多個并發(fā)事務(wù)之間數(shù)據(jù)要相互隔離. 持久性 一個事務(wù)一旦被提交,它對數(shù)據(jù)庫中數(shù)據(jù)的改變就是永久性的,即使數(shù)據(jù)庫發(fā)生故障也不應(yīng)該對其有任何影響.查看全部
-
PlatformTransactionManager事務(wù)管理器查看全部
-
在測試方法中,可以使用RunWith的注解和ContextConfiguration的注解實現(xiàn)一些初始化工作 同時使用Resource注入需要測試的Bean @RunWith(SpringJUnit4ClassRunner.class) @ContextConfiguration("../../applicationContext4.xml") public class SpringDemo4 { // 注入代理類 @Resource(name = "accountService") private AccountService accountService; @Test public void demo1() { accountService.transfer("aaa", "bbb", 200d); } }查看全部
-
基于聲明式方式3 利用注解的方式 在xml中配置事務(wù)管理器,和開啟使用事務(wù)的注解 <!-- 配置事務(wù)管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 開啟注解事務(wù) --> <tx:annotation-driven transaction-manager="transactionManager"/> 在對應(yīng)需要事務(wù)管理的業(yè)務(wù)層上加上注解 @Transactional查看全部
-
基于聲明式的方式2 使用aspectj的xml配置方式 在xml文件中配置事務(wù)管理器,注入連接池 配置事務(wù)的通知,屬性設(shè)置應(yīng)用的方法和傳播行為等 配置切面,在切面中,配置切入點,和advisor把切入點和通知聯(lián)系在一起 <!-- 配置事務(wù)管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 配置事務(wù)的通知 --> <tx:advice id="txAdvice" transaction-manager="transactionManager"> <tx:attributes> <tx:method name="transfer" propagation="REQUIRED"/> </tx:attributes> </tx:advice> <!-- 配置切面 --> <aop:config> <!-- 配置切入點 --> <aop:pointcut expression="execution(* com.demo3.AccountService.*(..))" id="pointcut1"/> <!-- 配置切面 --> <aop:advisor advice-ref="txAdvice" pointcut-ref="pointcut1"/> </aop:config>查看全部
-
基于聲明式的方式1 在xml中配置事務(wù)管理器,注入連接池 配置代理,注入目標(biāo)對象,事務(wù)管理器,事務(wù)的屬性 <!-- 配置事務(wù)管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 配置業(yè)務(wù)層的代理 --> <bean id="accountServiceProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> <!-- 配置目標(biāo)對象 --> <property name="target" ref="accountService"></property> <!-- 注入事務(wù)管理器 --> <property name="transactionManager" ref="transactionManager"></property> <!-- 注入事務(wù)的屬性 --> <property name="transactionAttributes"> <props> <!-- 格式:PROPAGATION:事務(wù)的傳播行為, ISOLATION:事務(wù)的隔離級別, readOnly:只讀, -Exception:發(fā)生哪些異?;貪L事務(wù), +Exception:發(fā)生哪些異常不回滾 --> <prop key="transfer">PROPAGATION_REQUIRED</prop> </props> </property> </bean>查看全部
-
基于編程式實現(xiàn)事務(wù) 在xml中配置事務(wù)管理器,在其中注入連接池 配置事務(wù)管理的模版,在其中注入事務(wù)管理器 <!-- 配置事務(wù)管理器 --> <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource"></property> </bean> <!-- 配置事務(wù)管理的模版:Spring為了簡化事務(wù)管理的代碼而提供的類 --> <bean id="transactionTemplate" class="org.springframework.transaction.support.TransactionTemplate"> <property name="transactionManager" ref="transactionManager"></property> </bean> 在Service層中注入模版之后,使用transactionTemplate.execute()方法,在其中實現(xiàn)一個匿名內(nèi)部類,這個里面就同屬于一個事務(wù) public void transfer(String out, String in, Double money) { transactionTemplate.execute(new TransactionCallbackWithoutResult() { @Override protected void doInTransactionWithoutResult(TransactionStatus arg0) { accountDAO.OutMoney(out, money); int i = 1 / 0; accountDAO.InMoney(in, money); } }); }查看全部
-
使用spring提供的模版,進(jìn)行數(shù)據(jù)庫的操作 在xml中配置連接池 <!-- 配置DAO層類 --> <bean id="accountDAO" class="com.demo1.AccountDAOImpl"> <property name="dataSource" ref="dataSource"></property> </bean> 在類上繼承JdbcDaoSupport public void OutMoney(String out, Double money) { String sql = "update account set money = money - ? where name = ?"; this.getJdbcTemplate().update(sql, money, out); }查看全部
-
xml中引入外部文件的配置 c3p0連接池的配置 <!-- 引入外部屬性文件 --> <context:property-placeholder location="jdbc.properties"/> <!-- 配置c3p0的連接池 --> <bean id="dataSource" class="com.mchange.v2.c3p0.ComboPooledDataSource"> <property name="driverClass" value="${jdbc.driverClass}"></property> <property name="jdbcUrl" value="${jdbc.url}"></property> <property name="user" value="${jdbc.username}"></property> <property name="password" value="${jdbc.password}"></property> </bean>查看全部
-
TransactionStatus查看全部
舉報
0/150
提交
取消