读书人

Spring AOP配置死活不起作用

发布时间: 2014-01-23 14:48:04 作者: rapoo

Spring AOP配置死活不起作用,求救
无论怎么试都无法回滚

AOP配置如下:


<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx"
xsi:schemaLocation="http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx.xsd">

<!-- AOP事务 -->
<tx:advice id="DomainTxAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="delete*" propagation="REQUIRED"/>
<tx:method name="remove*" propagation="REQUIRED"/>
<tx:method name="update*" propagation="REQUIRED"/>
<tx:method name="save*" propagation="REQUIRED"/>
<tx:method name="create*" propagation="REQUIRED"/>
<tx:method name="insert*" propagation="REQUIRED"/>
<tx:method name="add*" propagation="REQUIRED"/>
<tx:method name="get*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="load*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="query*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="select*" propagation="SUPPORTS" read-only="true"/>
<tx:method name="find*" propagation="SUPPORTS" read-only="true"/>
</tx:attributes>
</tx:advice>

<aop:config proxy-target-class="true">
<aop:pointcut id="DomainServices" expression="execution(* rsj.frdc.domain..service..*.*(..))"/>
<aop:advisor pointcut-ref="DomainServices" advice-ref="DomainTxAdvice"/>
</aop:config>
</beans>


希望匹配的其中一个方法:
rsj.frdc.domain.datacleaner.schedule.fixplan.service.impl.DirtyRecordFixPlanService.save

方法中人为抛出一个异常:

public void save(DirtyRecordFixRule rule) {
dirtyRecordFixRuleDAO.insert(rule);
throw new RuntimeException("出错了!!!");
}


结果“dirtyRecordFixRuleDAO.insert(rule);”所插入的数据还是进数据库了,没有成功回滚。
[解决办法]
我怎么在配置文件里没看到楼主的事务管理器
你这个transactionManager的事务管理器没配置啊
[解决办法]
配置没看出来什么问题
"execution(* rsj.frdc.domain..service..*.*(..))"

这个和你包结构是对应的吗?
[解决办法]
有些表的表类型是不支持事务回滚的 确定其他没什么问题 在考虑下这个问题
[解决办法]
需要在调用这个方法的地方捕获抛出的异常
[解决办法]
<aop:pointcut id="DomainServices" expression="execution(*rsj.frdc.domain..service.impl..*.*(..))"/>
这个样子试试
[解决办法]
execution(* rsj.frdc.domain.*.service.*.*(..))试试
[解决办法]
你的

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

<bean id="oracleDataSource" class="oracle.jdbc.pool.OracleDataSource">



<property name="dataSource" ref="dataSource"/> 不应该是 oracleDataSource 吗????
[解决办法]
打印一下 service是否代理成功了

读书人网 >Java Web开发

热点推荐