TransactionAttributeSource,TransactionAttribute

[b][/b][b]每一个方法执行都会应用事务,它回传的transactionAttribute实例的默认传播行为是PROPAGATION_REQUIRED,隔离层级为ISOLATION_REFAULE[/b]

<bean id="informationDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="proxyInterfaces">
<list>
<value>
com.gsvince.hibernate.Idao.IInformationDAO
</value>
</list>
</property>
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="informationDAO" />
</property>
<property name="transactionAttributeSource">
<ref bean="transactionAttributeSource"/>
</property>
</bean>

<bean id="transactionAttributeSource" class="org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource">
</bean>


[b]也可以使用org.springframework.transaction.interceptor.DefaultTransactionAttribute,并设置自己的事务策略,之后设置给transactionAttributeSource,例如:[/b]

<bean id="myTransactionAttribute" class="org.springframework.transaction.interceptor.DefaultTransactionAttribute">
<property name="propagationBehaviorName"
value="PROPAGATION_REQUIRES_NEW"/>
<property name="isolationLevelName"
value="ISOLATION_REPEATABLE_READ"/>
</bean>

<bean id="transactionAttributeSource" class="org.springframework.transaction.interceptor.MatchAlwaysTransactionAttributeSource">
<property name="transactionAttribute"
ref="myTransactionAttribute"/>
</bean>

<bean id="informationDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="proxyInterfaces">
<list>
<value>
com.gsvince.hibernate.Idao.IInformationDAO
</value>
</list>
</property>
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="informationDAO" />
</property>
<property name="transactionAttributeSource"
ref="transactionAttributeSource"/>
</bean>


[b]也可以使用org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource来指定某些方法要应用事务,以及要应用的事务策略,例如:[/b]

<bean id="transactionAttributeSource" class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource">
<property name="properties">
<props>
<prop key="edit*">PROPAGATION_REQUIRED</prop>
<prop key="insert*">PROPAGATION_REQUIRED</prop>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="delete*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>

<bean id="informationDAOProxy" class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean">
<property name="proxyInterfaces">
<list>
<value>
com.gsvince.hibernate.Idao.IInformationDAO
</value>
</list>
</property>
<property name="transactionManager">
<ref bean="transactionManager" />
</property>
<property name="target">
<ref local="informationDAO" />
</property>
<property name="transactionAttributeSource"
ref="transactionAttributeSource"/>
</bean>

[b]在NameMatchTransactionAttributeSource的"properties"属性上,可以指定方法名称与事务策略,方法名称的指定可以指定全名,也可以使用Wildcard来指定,例如上面的指定中,只要方法名以insert开头的都会应用相对应的事务策略。[/b]
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值