當前位置:
首頁 >
前端技术
> javascript
>内容正文
javascript
Spring-学习笔记10【Spring事务控制】
生活随笔
收集整理的這篇文章主要介紹了
Spring-学习笔记10【Spring事务控制】
小編覺得挺不錯的,現在分享給大家,幫大家做個參考.
- Java后端 學習路線 筆記匯總表【黑馬程序員】
目錄
01 基于XML的AOP實現事務控制
02 作業-基于注解的AOP實現事務控制及問題分析_上
03 作業-基于注解的AOP實現事務控制及問題分析_下
04 spring中事務控制的一組API
05 spring事務控制的代碼準備
06 spring基于XML的聲明式事務控制-配置步驟
06.1、bean.xml
07 spring基于注解的聲明式事務控制
08 spring基于純注解的聲明式事務控制
09 spring編程式事務控制1-了解
10 spring編程式事務控制2-了解
11 spring5新特性的介紹
11.1、Test.java
01 基于XML的AOP實現事務控制
02 作業-基于注解的AOP實現事務控制及問題分析_上
03 作業-基于注解的AOP實現事務控制及問題分析_下
注解AOP控制事務的問題分析04 spring中事務控制的一組API
05 spring事務控制的代碼準備
06 spring基于XML的聲明式事務控制-配置步驟
06.1、bean.xml
<?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:aop="http://www.springframework.org/schema/aop"xmlns:tx="http://www.springframework.org/schema/tx"xsi:schemaLocation="http://www.springframework.org/schema/beanshttp://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/txhttp://www.springframework.org/schema/tx/spring-tx.xsdhttp://www.springframework.org/schema/aophttp://www.springframework.org/schema/aop/spring-aop.xsd"><!-- 配置業務層 --><bean id="accountService" class="com.itheima.service.impl.AccountServiceImpl"><property name="accountDao" ref="accountDao"></property></bean><!-- 配置賬戶的持久層 --><bean id="accountDao" class="com.itheima.dao.impl.AccountDaoImpl"><property name="dataSource" ref="dataSource"></property></bean><!-- 配置數據源 --><bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"><property name="driverClassName" value="com.mysql.jdbc.Driver"></property><property name="url" value="jdbc:mysql://localhost:3306/eesy"></property><property name="username" value="root"></property><property name="password" value="root"></property></bean><!-- spring中基于XML的聲明式事務控制配置步驟1、配置事務管理器2、配置事務的通知此時我們需要導入事務的約束 tx名稱空間和約束,同時也需要aop的使用tx:advice標簽配置事務通知屬性:id:給事務通知起一個唯一標識transaction-manager:給事務通知提供一個事務管理器引用3、配置AOP中的通用切入點表達式4、建立事務通知和切入點表達式的對應關系5、配置事務的屬性是在事務的通知tx:advice標簽的內部 --><!-- 配置事務管理器 --><bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"><property name="dataSource" ref="dataSource"></property></bean><!-- 配置事務的通知 --><tx:advice id="txAdvice" transaction-manager="transactionManager"><!-- 配置事務的屬性isolation:用于指定事務的隔離級別。默認值是DEFAULT,表示使用數據庫的默認隔離級別。propagation:用于指定事務的傳播行為。默認值是REQUIRED,表示一定會有事務,增刪改的選擇。查詢方法可以選擇SUPPORTS。read-only:用于指定事務是否只讀。只有查詢方法才能設置為true。默認值是false,表示讀寫。timeout:用于指定事務的超時時間,默認值是-1,表示永不超時。如果指定了數值,以秒為單位。rollback-for:用于指定一個異常,當產生該異常時,事務回滾;產生其他異常時,事務不回滾;沒有默認值,表示任何異常都回滾。no-rollback-for:用于指定一個異常,當產生該異常時,事務不回滾,產生其他異常時事務回滾。沒有默認值。表示任何異常都回滾。 --><tx:attributes><tx:method name="*" propagation="REQUIRED" read-only="false"/><tx:method name="find*" propagation="SUPPORTS" read-only="true"></tx:method></tx:attributes></tx:advice><!-- 配置aop --><aop:config><!-- 配置切入點表達式 --><aop:pointcut id="pt1" expression="execution(* com.itheima.service.impl.*.*(..))"></aop:pointcut><!-- 建立切入點表達式和事務通知的對應關系 --><aop:advisor advice-ref="txAdvice" pointcut-ref="pt1"></aop:advisor></aop:config> </beans>07 spring基于注解的聲明式事務控制
08 spring基于純注解的聲明式事務控制
09 spring編程式事務控制1-了解
10 spring編程式事務控制2-了解
編程式事務11 spring5新特性的介紹
11.1、Test.java
jdk8和Jdk7的對比 package com.itheima.test;import java.lang.reflect.Method;/*** @author 黑馬程序員* @Company http://www.ithiema.com* @Version 1.0*/ public class Test {//循環次數定義:10億次private static final int loopCnt = 1000 * 1000 * 1000;public static void main(String[] args) throws Exception {//輸出jdk的版本System.out.println("java.version=" + System.getProperty("java.version"));t1();t2();t3();}// 每次重新生成對象public static void t1() {long s = System.currentTimeMillis();for (int i = 0; i < loopCnt; i++) {Person p = new Person();p.setAge(31);}long e = System.currentTimeMillis();System.out.println("循環10億次創建對象的時間:" + (e - s));}// 同一個對象public static void t2() {long s = System.currentTimeMillis();Person p = new Person();for (int i = 0; i < loopCnt; i++) {p.setAge(32);}long e = System.currentTimeMillis();System.out.println("循環10億次給同一對象賦值的時間: " + (e - s));}// 使用反射創建對象public static void t3() throws Exception {long s = System.currentTimeMillis();Class<Person> c = Person.class;Person p = c.newInstance();Method m = c.getMethod("setAge", Integer.class);for (int i = 0; i < loopCnt; i++) {m.invoke(p, 33);}long e = System.currentTimeMillis();System.out.println("循環10億次反射創建對象的時間:" + (e - s));}static class Person {private int age = 20;public int getAge() {return age;}public void setAge(Integer age) {this.age = age;}} } jdbctemplate和queryrunner的區別總結
以上是生活随笔為你收集整理的Spring-学习笔记10【Spring事务控制】的全部內容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: Java-IntelliJ IDEA【@
- 下一篇: 操作系统【抢占式处理机调度例题、LLF最