首页 新闻 会员 周边

Spring有关AOP和事务问题xml标签共同使用时,事务不起作用问题

0
悬赏园豆:5 [待解决问题]

最近在学习Spring的知识,在用“xml+注解”方式配置AOP和事务的时候,用到<aop:aspectj-autoproxy/>和<tx:annotation-driven transaction-manager="transactionManager"/>两个标签,其中单独用到任何一个都可以生效;但是当2个标签一起配置的时候,手动在修改方法里面写了个异常(int a = 1/0),aop倒是可以用,但是事务配置就不生效了,不知道是什么原因。具体在.xml文件里面配置很简单,如下:

复制代码
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
       xmlns:context="http://www.springframework.org/schema/context"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
       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.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
        http://www.springframework.org/schema/tx
        http://www.springframework.org/schema/tx/spring-tx.xsd
        ">

        <context:component-scan base-package="yt"></context:component-scan>
            
     <!-- 下面两个任意注释一个都能正常使用,2个一起出现的时候事务管理就不起作用了 --> <aop:aspectj-autoproxy/> <tx:annotation-driven transaction-manager="transactionManager"/> </beans>
复制代码

请各位大神能解小弟疑惑,感激不尽

独孤小败ai的主页 独孤小败ai | 初学一级 | 园豆:197
提问于:2018-08-23 17:52

后来发现,在使用5种通知中,使用前置通知,后置通知,异常通知,最终通知的注解都没问题,唯独当且仅当只有配置环绕通知的注解的时候使用上述xml配置时,事务配置会不起作用

独孤小败ai 5年前
< >
分享
所有回答(1)
1

你好,请问,你找到这个问题的答案了吗?

uuc33 | 园豆:202 (菜鸟二级) | 2019-02-19 17:35

并没有

支持(0) 反对(0) 独孤小败ai | 园豆:197 (初学一级) | 2019-09-20 16:51
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册