• Ldap遇到了事务管理问题


    JDBC 和 LDAP 的事务管理

    参考:http://www.linuxidc.com/Linux/2016-10/135718.htm

    事务在项目中是必须考虑的一部分,这节讨论两种事务的分别处理和结合,通过注解来完成。 典型的JDBC事务配置如下:

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

    我们配置了jdbc的默认事务管理为txManager,在服务层我们可以使用注解@Transcational来标注事务。

    在单独需要ldap事务管理时,我们可以配置ldap的事务,起了个别名ldapTx:

    <bean id="ldapTxManager"
    class="org.springframework.ldap.transaction.compensating.manager.ContextSourceTransactionManager">
        <property name="contextSource" ref="contextSource" /><qualifier value="ldapTx"/></bean>

    我们可以使用注解@Transactional("ldapTx")来标注ldap的事务,如果不想每次引用别名,使用@LdapTransactional,则可以创建注解:

    import java.lang.annotation.ElementType;
    import java.lang.annotation.Retention;
    import java.lang.annotation.RetentionPolicy;
    import java.lang.annotation.Target;
    
    import org.springframework.transaction.annotation.Transactional;
    
    @Target({ ElementType.METHOD, ElementType.TYPE })
    @Retention(RetentionPolicy.RUNTIME)
    @Transactional("ldapTx")
    public @interface LdapTransactional {
    
    }

    在ldap和jdbc同时都有操作的服务中,我们可以配置ContextSourceAndDataSourceTransactionManager来实现事务管理:

    <beanid="ldapJdbcTxManager"class="org.springframework.ldap.transaction.compensating.manager.ContextSourceAndDataSourceTransactionManager">  
        <property name="contextSource" ref="contextSource"/>  
        <property name="dataSource" ref="dataSource" />  
        <qualifiervalue="ldapJdbcTx"/>
    </bean>
  • 相关阅读:
    课程设计第二十二天,09.09
    课程设计第二十一天,09.08
    课程设计第二十天,09.07
    课程设计第十九天,09.06
    课程设计第十八天,09.05
    课程设计第十七天,09.04
    数词、介词、连词
    形容词、副词
    情态动词、非谓语动词、虚拟语气、独立主格结构
    词法、句法、短语、从句和句子、主谓一致、特殊句式
  • 原文地址:https://www.cnblogs.com/Actexpler-S/p/7895050.html
Copyright © 2020-2023  润新知