2 cxm77870428 cxm77870428 于 2016.09.07 12:16 提问

spring + mybatis 事物不起作用,无法回滚

spring + mybatis 事物不起作用,无法回滚:求解

设置如下:

<aop:aspectj-autoproxy proxy-target-class="true" />

<!-- 基于Druid数据库链接池的数据源配置 -->
<bean id="dataSource" class="com.alibaba.druid.pool.DruidDataSource" init-method="init" destroy-method="close">
    <property name="driverClassName" value="${jdbc.driver}" />
    <property name="url" value="${jdbc.url}" />
    <property name="username" value="${jdbc.username}" />
    <property name="password" value="${jdbc.password}" />
    <property name="initialSize" value="${pool.initialSize}" />
    <property name="minIdle" value="${pool.minIdle}" />
    <property name="maxActive" value="${pool.maxActive}" />
    <property name="maxWait" value="${pool.maxWait}" />
    <property name="timeBetweenEvictionRunsMillis" value="${pool.timeBetweenEvictionRunsMillis}" />
    <property name="minEvictableIdleTimeMillis" value="${pool.minEvictableIdleTimeMillis}" />
    <property name="testWhileIdle" value="true" />
    <property name="testOnBorrow" value="true" />
    <property name="testOnReturn" value="false" />
    <property name="validationQuery" value="${jdbc.validationQuery}" />
    <property name="filters" value="config" />
    <property name="connectionProperties" value="config.decrypt=true;config.decrypt.key=${jdbc.publickey}" />
</bean>

<!-- 将数据源映射到sqlSessionFactory中 -->
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource" />
    <property name="mapperLocations" value="classpath*:mapper/*.Mapper.xml" />
    <property name="configLocation" value="classpath:config/mybatis-config.xml" />
</bean>

<!-- SqlSession模板类实例 -->
<bean id="sessionTemplate" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="close">
    <constructor-arg index="0" ref="sqlSessionFactory" />
</bean>

<!--======= 事务配置 Begin ================= -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
    <property name="dataSource" ref="dataSource" />
</bean>
<!-- <aop:pointcut id="txPointcut" expression="execution(* com.enjoy.system.service..*(..)) or execution(* com.enjoy.commodity.service..*(..))" /> -->

<aop:config>
    <aop:pointcut id="txPointcut" expression="(execution(* com.enjoy.system.service..*(..)) or execution(* com.enjoy.commodity.service..*(..)))" />
    <aop:advisor pointcut-ref="txPointcut" advice-ref="txAdvice" />
</aop:config>

<tx:advice id="txAdvice" transaction-manager="transactionManager">
    <tx:attributes>
        <tx:method name="insert*" propagation="REQUIRED" />
        <tx:method name="save*" propagation="REQUIRED" />
        <tx:method name="add*" propagation="REQUIRED" />
        <tx:method name="set*" propagation="REQUIRED" />
        <tx:method name="update*" propagation="REQUIRED" />
        <tx:method name="edit*" propagation="REQUIRED" />
        <tx:method name="delete*" propagation="REQUIRED" />
        <tx:method name="remove*" propagation="REQUIRED" />
        <tx:method name="init*" propagation="REQUIRED" />
        <tx:method name="get*" propagation="REQUIRED" read-only="true" />
        <tx:method name="count*" propagation="REQUIRED" read-only="true" />
        <tx:method name="find*" propagation="REQUIRED" read-only="true" />
        <tx:method name="list*" propagation="REQUIRED" read-only="true" />
        <tx:method name="*" read-only="true" />
    </tx:attributes>
</tx:advice>

求解!!

3个回答

of214
of214   2016.09.07 12:28

看上去配置没有问题,贴一下java代码和日志
是不是service中的方法名不是以你配置的方法名开头的
可以看下这篇文章:http://58coding.com/article/detail/24667919514339873

fu415037685
fu415037685   2016.09.07 13:32

你的包是不是导入的全和正确

cxm77870428
cxm77870428   2016.09.08 11:52

service层:

package com.enjoy.commodity.service;

import java.util.List;
import java.util.Map;

import com.enjoy.commodity.entity.CommodityImage;

public interface CommodityImageService {

/**
 * 保存信息.
 * 
 * @param bean
 */
public void insert(CommodityImage entity);

/**
 * 批量保存
 * @param list
 */
public void insert(List<CommodityImage> list);

/**
 * 更新信息.
 * 
 * @param user
 */
public void update(CommodityImage entity);

/**
 * 根据ID获取信息.
 * 
 * @param userId
 * @return
 */
public CommodityImage getById(Long id);

/**
 * 根据ID删除
 * 
 * @param id 
 */
public void deleteById(Long id);

/**
 * 根据id批里删除
 * @param list
 */
public void deleteByIds(List<Map<String, Object>> list);

/**
 * 得到商品图片
 * @param map commodityid
 * @return
 */
public List<CommodityImage> listBy(Map<String, Object> map);

/**
 * 得到商品图片条数
 * @param map
 * @return
 */
public Long getCountByColumn(Map<String, Object> map);

}
图片说明

包也是对上的没有错误信息

Csdn user default icon
上传中...
上传图片
插入图片