frisk_zhou 2009-06-20 21:23
浏览 270
已采纳

spring和ibatis的整合!

对spring整合不是很熟悉。请问以下的配置是否包含了事务。是这个吗?baseTransactionProxy。
如果我把这段配置用于实际项目中。会不会有什么问题,请指教!谢谢
[code="java"]

<!--    
    以下是 ibatis的配置 -->
<bean id="propertyConfig" class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
   <property name="location">
        <value>classpath:jdbc.properties</value>
   </property>
 </bean>
 <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> 
        <property name="driverClassName" value="${jdbc.driver}" /> 
        <property name="url" value="${jdbc.url}" /> 
        <property name="username" value="${jdbc.username}" /> 
        <property name="password" value="${jdbc.password}" /> 
</bean> 
<!--根据dataSource和configLocation创建一个SqlMapClient-->
  <bean id="sqlMapClient" class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
       <property name="configLocation">
        <value>classpath:SqlMapConfig.xml</value>
       </property>
       <property name="dataSource">
        <ref bean="dataSource" />
       </property>
</bean>

<!--根据sqlMapClien创建一个SqlMapClient模版类-->




<!-- spring 的事务处理类配置 -->






<!-- spring 的事务处理代理配置 -->

<bean id="baseTransactionProxy"
    class="org.springframework.transaction.interceptor.TransactionProxyFactoryBean"  
    lazy-init="true" abstract="true">       
    <!-- 它有个属性叫“事务处理”,下面会声明的 -->  
    <property name="transactionManager">      
        <ref bean="transactionManagerIbatis" />  
    </property>             
    <!--这里就声明了具体的事务 -->      
    <property name="transactionAttributes">      
        <props>  
            <prop key="insert*">PROPAGATION_REQUIRED</prop>  
            <prop key="save*">PROPAGATION_REQUIRED</prop>  
            <prop key="update*">PROPAGATION_REQUIRED</prop>  
            <prop key="del*">PROPAGATION_REQUIRED</prop>  
            <prop key="modify*">PROPAGATION_REQUIRED</prop>  
            <prop key="*">PROPAGATION_REQUIRED,readOnly</prop>  
        </props>  
    </property>      
</bean>  

[/code]
[b]问题补充:[/b]
我的spring是这样配置的:
[code="java"]





[/code]
这样也没有问题吧?
To lovewhzlq
我还没有达到你说的境界。哪有有文章说明这个。我想看看。
我从来没有在软件公司做过。在企业里,而且是单打独斗。水平很差,只能是不停地学习。hibernate会一些,所以还想学习ibatis和JPA。唉,什么时候达到你那水平,

to huangnetian ,谢谢你的热心,有问题我一定会问的。!!

  • 写回答

6条回答 默认 最新

  • weixin_42297497 2009-06-22 09:20
    关注

    这样吧,我把我项目中的东西拿来发给你一份,你自己去慢慢琢磨吧,有不明白的就提.

    class="org.apache.commons.dbcp.BasicDataSource"
    destroy-method="close">
    value="${query.jdbc.driverClassName}" />









    <!--配置ibatis的资源文件载入-->
    <bean id="querySqlMapClient"
        class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="configLocation">
            <value>classpath:conf/sqlMap-config.xml</value>
        </property>
        <property name="dataSource">
            <ref local="queryDataSource" />
        </property>
    </bean>
    
    <bean id="updateDataSource"
        class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName"
            value="${update.jdbc.driverClassName}" />
        <property name="url" value="${update.jdbc.url}" />
        <property name="username" value="${update.jdbc.username}" />
        <property name="password" value="${update.jdbc.password}" />
        <property name="maxActive" value="100" />
        <property name="maxIdle" value="10" />
        <property name="maxWait" value="10000" />
        <property name="removeAbandoned" value="true" />
        <property name="removeAbandonedTimeout" value="60" />
        <property name="logAbandoned" value="true" />
    </bean>
    
    <!--配置ibatis的资源文件载入-->
    <bean id="updateSqlMapClient"
        class="org.springframework.orm.ibatis.SqlMapClientFactoryBean">
        <property name="configLocation">
            <value>classpath:conf/sqlMap-config.xml</value>
        </property>
        <property name="dataSource">
            <ref local="updateDataSource" />
        </property>
    </bean>
    
    <bean id="sqlMapDaoTemplate"
        class="com.incesoft.guess.dao.base.DefaultSqlMapDaoTemplate">
        <property name="querySqlMapClientTemplate">
            <bean
                class="org.springframework.orm.ibatis.SqlMapClientTemplate">
                <property name="sqlMapClient" ref="querySqlMapClient"></property>
            </bean>
        </property>
        <property name="updateSqlMapClientTemplate">
            <bean
                class="org.springframework.orm.ibatis.SqlMapClientTemplate">
                <property name="sqlMapClient"
                    ref="updateSqlMapClient">
                </property>
            </bean>
        </property>
    </bean>
    
    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource">
            <ref bean="updateDataSource" />
        </property>
    </bean>
    <bean id="transactionInterceptor" class="org.springframework.transaction.interceptor.TransactionInterceptor"> 
         <property name="transactionManager"> 
            <ref local="transactionManager" /> 
         </property> 
         <property name="transactionAttributes"> 
             <props>                  
                 <prop key="*">PROPAGATION_REQUIRED,-Exception</prop>  
             </props> 
         </property> 
     </bean> 
     <bean name="beanNameAutoProxy" class="org.springframework.aop.framework.autoproxy.BeanNameAutoProxyCreator" /> 
     <bean id="transactionProxy" parent="beanNameAutoProxy"> 
          <property name="beanNames"> 
              <list> 
                 <value>accountManager</value>
                 <value>guessManager</value>                 
              </list> 
          </property> 
          <property name="interceptorNames"> 
               <value>transactionInterceptor</value>  
          </property> 
     </bean> 
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(5条)

报告相同问题?

悬赏问题

  • ¥15 Error in check.length("fill") : 'gpar'成分'fill'的长度不能为零
  • ¥15 python:excel数据写入多个对应word文档
  • ¥60 全一数分解素因子和素数循环节位数
  • ¥15 ffmpeg如何安装到虚拟环境
  • ¥188 寻找能做王者评分提取的
  • ¥15 matlab用simulink求解一个二阶微分方程,要求截图
  • ¥30 乘子法解约束最优化问题的matlab代码文件,最好有matlab代码文件
  • ¥15 写论文,需要数据支撑
  • ¥15 identifier of an instance of 类 was altered from xx to xx错误
  • ¥100 反编译微信小游戏求指导