大博主 2017-11-06 09:35 采纳率: 38.9%
浏览 2942
已结题

spring加mybatis的事务配置,我如果不加事务方法是可以执行的,配置了事务没效果

 <?xml version="1.0" encoding="UTF-8"?>

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/beans" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context  
        http://www.springframework.org/schema/context/spring-context.xsd  
        http://www.springframework.org/schema/aop  
        http://www.springframework.org/schema/aop/spring-aop.xsd">

    <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource"
        destroy-method="close">
        <property name="driverClassName" value="org.gjt.mm.mysql.Driver" />
        <property name="url"
            value="jdbc:mysql://${datasource.cloudx.host}:${datasource.cloudx.port}/${datasource.cloudx.database}?useUnicode=true&amp;characterEncoding=UTF-8&amp;zeroDateTimeBehavior=convertToNull&amp;allowMultiQueries=true" />
        <property name="username" value="${datasource.cloudx.user}" />
        <property name="password" value="${datasource.cloudx.password}" />
        <property name="initialSize" value="5" />
        <property name="maxActive" value="50" />
        <property name="maxIdle" value="50" />
        <property name="minIdle" value="5" />
        <property name="maxWait" value="30000" />
        <property name="validationQuery" value="SELECT 1+1" />
        <property name="defaultAutoCommit" value="false" />
    </bean>

    <bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
        <property name="dataSource" ref="dataSource" />
        <property name="configLocation"
            value="classpath:conf-mybatis/mybatis-base.xml" />
        <property name="mapperLocations"
            value="classpath*:conf-mybatis/mybatis-mapper-*.xml" />
    </bean>

    <bean id="transactionManager"
        class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <property name="dataSource" ref="dataSource" />
    </bean>

    <tx:advice id="iccardTxAdvice" transaction-manager="transactionManager">  
        <tx:attributes>  
          <tx:method name="update*" propagation="REQUIRED" read-only="false" rollback-for="java.lang.Exception" />  
        </tx:attributes>  
    </tx:advice>  

    <aop:config>      
        <aop:pointcut id="iccardTerm" expression="execution(public * com.cessas.cloudx.service.*.*(..))" />  
        <aop:advisor pointcut-ref="iccardTerm" advice-ref="iccardTxAdvice" />  
    </aop:config>
    <tx:annotation-driven transaction-manager="transactionManager" />

</beans>

<?xml version="1.0" encoding="UTF-8"?>

<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns="http://www.springframework.org/schema/beans" xmlns:tx="http://www.springframework.org/schema/tx"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:aop="http://www.springframework.org/schema/aop"
    xsi:schemaLocation="http://www.springframework.org/schema/beans 
    http://www.springframework.org/schema/beans/spring-beans.xsd
       http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        http://www.springframework.org/schema/context  
        http://www.springframework.org/schema/context/spring-context.xsd  
        http://www.springframework.org/schema/aop  
        http://www.springframework.org/schema/aop/spring-aop.xsd">

    <aop:aspectj-autoproxy />

</beans>

  • 写回答

6条回答

  • meicuojiushiwoi 2017-11-06 09:50
    关注

    没效果是啥意思?数据库没有持久化?

    评论

报告相同问题?

悬赏问题

  • ¥15 github符合条件20分钟秒到账,github空投 提供github账号可兑换💰感兴趣的可以找我交流一下
  • ¥50 永磁型步进电机PID算法
  • ¥15 sqlite 附加(attach database)加密数据库时,返回26是什么原因呢?
  • ¥88 找成都本地经验丰富懂小程序开发的技术大咖
  • ¥15 如何处理复杂数据表格的除法运算
  • ¥15 如何用stc8h1k08的片子做485数据透传的功能?(关键词-串口)
  • ¥15 有兄弟姐妹会用word插图功能制作类似citespace的图片吗?
  • ¥200 uniapp长期运行卡死问题解决
  • ¥15 latex怎么处理论文引理引用参考文献
  • ¥15 请教:如何用postman调用本地虚拟机区块链接上的合约?