版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010741376/article/details/46584463
spring tx:advice 和 aop:config 配置事务 
关键字: eclipse不能识别<tx:advice/>标签 
<?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 " 
>

<bean id="transactionManager" 
        class="org.springframework.orm.hibernate3.HibernateTransactionManager" 
        abstract="false" lazy-init="default" autowire="default" 
        dependency-check="default"> 
        <property name="sessionFactory"> 
            <ref bean="sessionFactory" /> 
        </property> 
    </bean> 
    <tx:advice id="txAdvice" transaction-manager="transactionManager"> 
        <tx:attributes> 
            <tx:method name="add*" propagation="REQUIRED" /> 
            <tx:method name="delete*" propagation="REQUIRED" /> 
            <tx:method name="update*" propagation="REQUIRED" /> 
            <tx:method name="add*" propagation="REQUIRED" /> 
            <!-- <tx:method name="*" propagation="true" />--> 
        </tx:attributes>

</tx:advice>

<aop:config> 
        <aop:pointcut id="allManagerMethod" 
            expression="execution(* com.service.*.*(..))" /> 
        <aop:advisor advice-ref="txAdvice" 
            pointcut-ref="allManagerMethod" /> 
    </aop:config> 
</beans>

Eclipse不能识别<tx:advice/>标签

在开发Spring的过程中,有时会出现Eclipse不能识别<tx:advice/>标签。

提示出现以下错误:

The prefix "tx" for element "tx:advice" is not bound

这个错误的原因很简单是:

我们在定义申明AOP的时候。。没有加载schema。

具体表现如下:

<beans>

<tx:advice id="txAdvice" transaction-manager="transactionManager"> 
     <tx:attributes> 
         <tx:method name="get*" read-only="true"/> 
         <tx:method name="*" propagation="REQUIRES_NEW" rollback-for="Exception"/> 
     </tx:attributes> 
</tx:advice>

<!-- aop代理设置--> 
<aop:config proxy-target-class="true">   
....

</aop:config>

</beans>

这时会抛出异常不认<TX>标签。。起先还以为是没有加载JAR包呢。。

后来读AOP文档才发现<beans>中要加入“xmlns:aop”的命名申明,并在“xsi:schemaLocation”中指定aop配置的schema的地址

配置文件如下:

<?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 " 
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 ">

这些才是最关键的地方。。后面的配置不变。。。。

Spring使用 <tx:advice>和 <aop:config> 用来配置事务,具体如何配置你可以参考Spring文档。

我解释一下(* com.evan.crm.service.*.*(..))中几个通配符的含义:

第一个 * —— 通配 任意返回值类型 
第二个 * —— 通配 包com.evan.crm.service下的任意class 
第三个 * —— 通配 包com.evan.crm.service下的任意class的任意方法 
第四个 .. —— 通配 方法可以有0个或多个参数

综上:包com.evan.crm.service下的任意class的具有任意返回值类型、任意数目参数和任意名称的方法

<tx:advice/> 有关的设置

这一节里将描述通过 <tx:advice/> 标签来指定不同的事务性设置。默认的 <tx:advice/> 设置如下:

•事务传播设置是 REQUIRED

•隔离级别是 DEFAULT

•事务是 读/写

•事务超时默认是依赖于事务系统的,或者事务超时没有被支持。

•任何 RuntimeException 将触发事务回滚,但是任何 checked Exception 将不触发事务回滚

spring tx:advice 和 aop:config 配置事务相关推荐

  1. spring tx:advice 和 aop:config 配置事务 1

    <?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.sp ...

  2. spring tx:advice事务配置

    http://www.cnblogs.com/rushoooooo/archive/2011/08/28/2155960.html 链接归纳的很详细 首先在/WEB-INF/applicationCo ...

  3. Spring Cloud Alibaba - 19 Nacos Config配置中心加载不同微服务的通用配置的两种方式

    文章目录 Pre 实现 方式一 通过 shared-dataids 方式 方式二 通过 ext-config方式 配置文件优先级 源码 Pre Spring Cloud Alibaba - 18 Na ...

  4. Spring Cloud Alibaba - 18 Nacos Config配置中心加载相同微服务的不同环境下的通用配置

    文章目录 需求 实现 Step 1 Nacos Config 新增公共配置 Step 2 验证 配置文件优先级 源码 需求 举个例子,同一个微服务,通常我们的servlet-context 都是相同的 ...

  5. Spring Boot 中使用 @Transactional 注解配置事务管理

    From: https://blog.csdn.net/nextyu/article/details/78669997 事务管理是应用系统开发中必不可少的一部分.Spring 为事务管理提供了丰富的功 ...

  6. spring tx:advice(转)

    默认的 <tx:advice/> 设置如下: 事务传播设置是 REQUIRED 隔离级别是 DEFAULT 事务是 读/写 事务超时默认是依赖于事务系统的,或者事务超时没有被支持. 任何 ...

  7. Spring tx:advice/

    <tx:advice/> 有关的设置 这一节里将描述通过 <tx:advice/> 标签来指定不同的事务性设置.默认的 <tx:advice/> 设置如下: 事务传 ...

  8. Spring Cloud Alibaba - 17 Nacos Config 配置中心 应用篇

    文章目录 Nacos配置中心基础概念 配置服务 (Configuration Service) 配置管理 (Configuration Management) 配置项 配置集 配置集 ID 配置分组 ...

  9. 事务配置_SSH(五)- 使用注解方式配置事务管理

    步骤1:修改applicationContext.xml步骤2:为ProductServiceImpl 添加注解步骤3:测试步骤4:MYSQL 表的类型必须是INNODB才支持事务 步骤 1 : 修改 ...

最新文章

  1. Hibernate的条件查询的几种方式
  2. 中国首个海底数据中心样机测试数据揭晓,达世界先进能效水平
  3. 智能小程序档案馆——如何给“包”瘦身
  4. wxPython中文教程 简单入门加实例
  5. stc89c51单片机音乐盒系统设计_基于单片机的火控系统语音报读设计
  6. log4c移植到android,使用Android Studio调用C++ 代码-log4cplus
  7. 那些“不顾一切”要搞开源的人,现在怎样了?
  8. OpenCV-Laplacian边缘检测
  9. 多目标优化系列1---NSGA2的非支配排序函数的讲解
  10. 一点浩然气,千里快哉风
  11. golang隐藏window系统下自身cmd窗口
  12. Redis 集群可用性测试
  13. matlab自动识别技术,基于Matlab的车牌自动识别技术研究与实现
  14. 楼宇自动化专用BACnet网关BL103
  15. ros安装教程unbuntu20.04
  16. [BZOJ 3864][HDU 4899]Hero meet devil(DP套DP)
  17. 深信服超融合不兼容 lenovo SR650 板载X722网卡微码处理
  18. 瑞星升级提示网络连接失败网络配置后重试(12007) 解决办法
  19. logit回归模型假设_机器学习基础---逻辑回归(假设函数与线性回归不同)
  20. 分享 2 种规划思维和 4 个规划方法

热门文章

  1. Keil uvision 5 MDK 安装教程
  2. MATLAB | matlab运行、下载链接及21个matlab基本图像调试代码
  3. 阿里云 nginx php mysql_阿里云 Ubuntu + Nginx + PHP + MySQL
  4. win32程序启用控制台-- 调试输出
  5. MFC BEGIN_MESSAGE_MAP()
  6. 工业用微型计算机(11)-指令系统(8)
  7. 讨论下直博和读完硕士再读博,在能力上的差距
  8. 【Python】掌握Python中的索引和切片
  9. 里程碑!我的github排名进入前100名!
  10. 神经网络十大学习率衰减提效策略