`
bcc123hf
  • 浏览: 47802 次
  • 性别: Icon_minigender_1
  • 来自: 北京
社区版块
存档分类
最新评论

spring事务说明和简单实例-2

阅读更多
二声明式事务:
声明式事务用于管理自己写的dao,service层.一般dao不是extends或implements spring的接口或类.

如:
<bean id="transactionManager"
class="org.springframework.orm.hibernate3.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory" />
</bean>

<bean id="transactionInterceptor"
class="org.springframework.transaction.interceptor.TransactionInterceptor">
<!--  事务拦截器bean需要依赖注入一个事务管理器 -->
<property name="transactionManager" ref="transactionManager" />
<property name="transactionAttributes">
<!--  下面定义事务传播属性-->
<props>
<prop key="get*">PROPAGATION_REQUIRED,readOnly</prop>
<prop key="dealChrData">PROPAGATION_REQUIRED,ISOLATION_READ_COMMITTED</prop>
<prop key="*">PROPAGATION_REQUIRED</prop>
</props>
</property>
</bean>
    
    <!-- 定义BeanNameAutoProxyCreator-->
    <bean class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator">
    <!--  指定对满足哪些bean name的bean自动生成业务代理 -->
    <property name="beanNames">
            <!--  下面是所有需要自动创建事务代理的bean-->
            <list>
                <value>*Service*</value>
            </list>
            <!--  此处可增加其他需要自动创建事务代理的bean-->
    </property>
        <!--  下面定义BeanNameAutoProxyCreator所需的事务拦截器-->
        <property name="interceptorNames">
            <list>
                <!-- 此处可增加其他新的Interceptor -->
                <value>transactionInterceptor</value>
            </list>
        </property>
    </bean>

注意配置事务和隔离级别
分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics