选项1,更改您的配置以在接口级别注入事务:
<aop:config> <aop:pointcut id="createOperation" expression="execution(* org.andrea.myexample.myDeclarativeTransactionSpring.StudentDAO.create(..))" /> <aop:advisor advice-ref="txAdvice" pointcut-ref="createOperation" /></aop:config>
并获取该bean作为该接口的实例:
StudentDAO studentDao = (StudentDAO) context.getBean("studentJDBCTemplate");选项2,指示代理应使用
proxy-target-class属性扩展目标类:
<aop:config proxy-target-> ...</aop:config>
第一个选择是更清洁的选择,但是坦率地说,我更喜欢
@Transactional在Spring bean
XML中使用注释而不是AOP声明。有时很难使后者正确,如果您没有对组件进行特定的事务性测试,则 不一定 会 发现事情不正确 。



