"通配符的匹配很全面, 但无法找到元素 'tx:annotation-driven' 的声明"2018.10.28,Spring5.0.7事务TransactionManager的xml配置

spring开启事务配置tx,aop时候测试,报出一大堆错误;
其中有:
①"通配符的匹配很全面, 但无法找到元素 ‘tx:annotation-driven’ 的声明"
②URI必须偶数个
③加载applicationContext失败
④找不到 tx:advice

是因为xml头部各种原因有可能重复,有可能缺少约束、、、,直接copy一份头部替换掉原来的头部就行了;

<?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:aop="http://www.springframework.org/schema/aop"
       xmlns:tx="http://www.springframework.org/schema/tx"
       xmlns:context="http://www.springframework.org/schema/context"
       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/aop
              http://www.springframework.org/schema/aop/spring-aop.xsd
                http://www.springframework.org/schema/context
              http://www.springframework.org/schema/context/spring-context.xsd">

事务配置如下:
(1)daoImpl 继承了 JdbcDaoSupport 来获取 JdbcTemplate ,简化了applicationContext.xml 的 bean 配置;
(2)事务需要tx、aop命名空间约束配置,使用到了切入点表达式通知;@Pointcut(“execution(* com.baidu.service.impl..(…))”);

配置事务:

   <!--  配置事务  transactionManager -->
    <bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
        <!--向事务中注入源数据-->
        <property name="dataSource" ref="dataSource"></property>
    </bean>

配置 tx 事务的属性;

  <!--  配置 事务的属性 、find开头的方法只读事务,其他 -->
    <tx:advice id="interceptor" transaction-manager="transactionManager">
        <tx:attributes>
            <tx:method name="find*" read-only="true"/>
            <tx:method name="*"/>
        </tx:attributes>
    </tx:advice>

配置 aop 事务的切面‘’;

   <!--配置事务的切面-->
    <aop:config>
        <!-- 设置 pointcut   表达式,并且把定义好事务属性的应用到切入点  -->
        <aop:pointcut id="pt1" expression="execution(* com.baidu.serviceImpl.AccountServiceImpl.*(..))"></aop:pointcut>
        <aop:advisor advice-ref="interceptor" pointcut-ref="pt1"/>
    </aop:config>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值