spring 配置事務 配置檔案方式

2021-07-09 10:40:48 字數 801 閱讀 8922

<?xml version="1.0" encoding="gbk"?>

xmlns:xsi="" xmlns:aop=""

xmlns:tx="" xmlns:jdbc=""

xmlns:p=""

xsi:schemalocation=" /spring-beans-3.0.xsd

/spring-jdbc-3.0.xsd

/spring-aop-3.0.xsd

/spring-tx-3.0.xsd">  

destroy-method="close">

p:datasource-ref="datasource" p:configlocation="classpath:config/mybatis-config.xml" />

class="org.springframework.jdbc.datasource.datasourcetransactionmanager"> 

1.配置檔案方式

其中主要配置中是tx:advice和aop:config兩個配置節,以spring aop的方式實現事務管理。

tx:advice配置了事務的管理者是transactionmanager

,同時tx:method也規定了如果方法名匹配「add*」和「get*」方法時使用事務,propagation是設定事務的傳播級別。除了updatewelfare方法,其他的方法的事務是唯讀的(典型地,對於只執行查詢的事務你會將該屬性設為true,如果出現了更新、插入或是刪除語句時唯讀事務就會失敗)

aop:config指定了乙個aop:pointcut去引用上邊的advice。

spring配置檔案

1 配置檔案的簡化 1 屬性的 property name foo value foovalue value property 簡化為 property name foo value foovalue 2 引用bean property name foo ref bean foobean prope...

spring配置檔案

context annotation config 是用於啟用那些已經在spring容器裡註冊過的bean上面的註解,也就是顯示的向spring註冊 autowiredannotationbeanpostprocessor commonannotationbeanpostprocessor pers...

Spring配置檔案載入外部配置檔案

有時,應用程式可能需要從不同的位置 例如 檔案系統 classpath或者url 讀取外部資源 例如 文字檔案 xml檔案 屬性檔案或或者影象檔案 通常,為了從不同位置載入資源,需要和不同的api打交道。spring的資源載入器提供了乙個統一的getresource 方法,使用這個方法可以通過資源路...