[b][/b][b]每一个方法执行都会应用事务,它回传的transactionAttribute实例的默认传播行为是PROPAGATION_REQUIRED,隔离层级为ISOLATION_REFAULE[/b]
[b]也可以使用org.springframework.transaction.interceptor.DefaultTransactionAttribute,并设置自己的事务策略,之后设置给transactionAttributeSource,例如:[/b]
[b]也可以使用org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource来指定某些方法要应用事务,以及要应用的事务策略,例如:[/b]
[b]在NameMatchTransactionAttributeSource的"properties"属性上,可以指定方法名称与事务策略,方法名称的指定可以指定全名,也可以使用Wildcard来指定,例如上面的指定中,只要方法名以insert开头的都会应用相对应的事务策略。[/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]