大博主 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
    关注

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

    评论

报告相同问题?

悬赏问题

  • ¥20 搭建pt1000三线制高精度测温电路
  • ¥15 使用Jdk8自带的算法,和Jdk11自带的加密结果会一样吗,不一样的话有什么解决方案,Jdk不能升级的情况
  • ¥15 画两个图 python或R
  • ¥15 在线请求openmv与pixhawk 实现实时目标跟踪的具体通讯方法
  • ¥15 八路抢答器设计出现故障
  • ¥15 opencv 无法读取视频
  • ¥15 按键修改电子时钟,C51单片机
  • ¥60 Java中实现如何实现张量类,并用于图像处理(不运用其他科学计算库和图像处理库))
  • ¥20 5037端口被adb自己占了
  • ¥15 python:excel数据写入多个对应word文档