欢迎访问 生活随笔!

尊龙游戏旗舰厅官网

当前位置: 尊龙游戏旗舰厅官网 > 编程资源 > 编程问答 >内容正文

编程问答

spring tx:advice 和 aop:config 配置事务 -尊龙游戏旗舰厅官网

发布时间:2025/1/21 编程问答 3 豆豆
尊龙游戏旗舰厅官网 收集整理的这篇文章主要介绍了 spring tx:advice 和 aop:config 配置事务 小编觉得挺不错的,现在分享给大家,帮大家做个参考.
尊龙游戏旗舰厅官网的版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u010741376/article/details/46584463 spring tx:advice 和 aop:config 配置事务 
关键字: eclipse不能识别标签 
 


    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 " 



        class="org.springframework.orm.hibernate3.hibernatetransactionmanager" 
        abstract="false" lazy-init="default" autowire="default" 
        dependency-check="default"> 
         
             
         
   
 

     
         
             
             
             
             
             
         

     

     
       
            expression="execution(* com.service.*.*(..))" /> 
       
            pointcut-ref="allmanagermethod" /> 
     
 



eclipse不能识别标签 

在开发spring的过程中,有时会出现eclipse不能识别标签。 

提示出现以下错误: 

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



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

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

具体表现如下: 

 

 
      
          
          
      
 

 
   
.... 

 

 

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

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

配置文件如下: 

 

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使用 用来配置事务,具体如何配置你可以参考spring文档。 

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

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

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


有关的设置 

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



•事务传播设置是 required 

•隔离级别是 default 

•事务是 读/写 

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

•任何 runtimeexception 将触发事务回滚,但是任何 checked exception 将不触发事务回滚 

总结

以上是尊龙游戏旗舰厅官网为你收集整理的spring tx:advice 和 aop:config 配置事务的全部内容,希望文章能够帮你解决所遇到的问题。

如果觉得尊龙游戏旗舰厅官网网站内容还不错,欢迎将尊龙游戏旗舰厅官网推荐给好友。

网站地图