开发者

setting isolation level in spring annotation-based transactions

开发者 https://www.devze.com 2023-02-15 02:18 出处:网络
I use in my project annotation-based transaction management (I annotate some methods with @Transactional). I would like t开发者_运维问答o set the isolation level globally (not by putting it as an argu

I use in my project annotation-based transaction management (I annotate some methods with @Transactional). I would like t开发者_运维问答o set the isolation level globally (not by putting it as an argument to each @Transactional annotation).

Is it possible configure that in the XML? Currently my xml configuration contains

<tx:annotation-driven transaction-manager="txManager"/>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
   <property name="dataSource" ref="dataSource" />
</bean>

Is it possible to add the isolation somehow to tx:annotation-driven?


Spring's transaction management sets the transaction isolation on the Connection if you configure a non-default transaction isolation (by specifying it in a @Transactional annotation for example). If you can configure the transaction isolation of the connections while ensuring no other mechanism changes the transaction isolation of the connections, then you in effect globally set the transaction isolation used by the application.

For example, the Commons DBCP BasicDataSource class defines the defaultTransactionIsolation property to set the transaction isolation of connections returned from the pool:

<bean
    id="dataSource"
    class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
  <property name="driverClassName" value="${jdbc.driverClassName}"/>
  <property name="url" value="${jdbc.url}"/>
  <property name="username" value="${jdbc.username}"/>
  <property name="password" value="${jdbc.password}"/>
  <property name="defaultTransactionIsolation">
    <util:constant static-field="java.sql.Connection.TRANSACTION_READ_COMMITTED"/>
  </property>
</bean>
0

精彩评论

暂无评论...
验证码 换一张
取 消