posts - 495,comments - 227,trackbacks - 0

   这个配置文件是我做SSH的时候用的片断,用Spring来管理事务: 
<!-- spring代理hibernate事务的两种方法 --> 
     
    <!-- 不管采用哪种方法 下面的这个bean都是必须的 --> 
     
    <bean id="transactionManager" 
        class="org.springframework.orm.hibernate3.HibernateTransactionManager"> 
        <property name="sessionFactory"> 
            <ref local="sessionFactory" /> 
        </property> 
    </bean> 
     
    <!-- 1、spring事务代理模板 --> 
     
    <!-- 需要事务的Service类要继承下面的bean,使用方法如下--> 
     
    <!--  
    <bean id="txProxyTemplate" abstract="true" 
                   class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"> 
        <property name="transactionManager"> 
            <ref bean="transactionManager"/> 
        </property> 
        <property name="transactionAttributes"> 
            <props> 
                <prop key="save*">PROPAGATION_REQUIRED</prop> 
                <prop key="del*">PROPAGATION_REQUIRED</prop> 
                <prop key="change*">PROPAGATION_REQUIRED</prop> 
                <prop key="*">PROPAGATION_REQUIRED,readOnly</prop> 
            </props> 
        </property> 
    </bean> 
     
    <bean id="StudentDaoHibernate" 
        class="com.lideedu.yame.dao.hibernate.StudentDAOHibernateImpl" 
        singleton="false"> 
        <property name="sessionFactory"> 
            <ref bean="sessionFactory" /> 
        </property> 
        <property name="classService"> 
            <ref bean="ClassService" /> 
        </property> 
    </bean> 
     
    <bean id="StudentServiceTarget" 
        class="com.lideedu.yame.business.IStudentServiceImpl" singleton="false"> 
        <property name="studentDAO"> 
            <ref bean="StudentDaoHibernate" /> 
        </property> 
    </bean> 
     
    <bean id="StudentService" parent="txProxyTemplate"> 
        <property name="target"> 
            <ref bean="StudentServiceTarget"/> 
        </property> 
    </bean> 
     
    -->     
         
    <!-- 2、spring事务自动代理 --> 
     
    <!-- 需要事务的方法只要方法名和下面的模式匹配就可以接受Spring的事务代理 --> 
     
    <bean id="autoProxy" 
        class="org.springframework.aop.framework.autoproxy.DefaultAdvisorAutoProxyCreator"> 
    </bean> 
    <bean id="transactionAttributeSource" 
      class="org.springframework.transaction.interceptor.NameMatchTransactionAttributeSource"> 
        <property name="properties"> 
            <props> 
                <prop key="save*">PROPAGATION_REQUIRED</prop> 
                <prop key="update*">PROPAGATION_REQUIRED</prop>             
                <prop key="del*">PROPAGATION_REQUIRED</prop> 
                <prop key="change*">PROPAGATION_REQUIRED</prop>         
            </props> 
        </property> 
    </bean> 
    <bean id="transactionInterceptor" 
        class="org.springframework.transaction.interceptor.TransactionInterceptor"> 
        <property name="transactionManager"> 
            <ref bean="transactionManager" /> 
        </property> 
        <property name="transactionAttributeSource"> 
            <ref bean="transactionAttributeSource" /> 
        </property> 
    </bean> 
    <bean id="transactionAdvisor" 
        class="org.springframework.transaction.interceptor.TransactionAttributeSourceAdvisor"> 
        <constructor-arg> 
            <ref bean="transactionInterceptor" /> 
        </constructor-arg> 
</bean> 

posted on 2007-12-21 23:33 SIMONE 阅读(1300) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: