zoukankan      html  css  js  c++  java
  • Spring注释事务失效及解决办法

    如果带上事务,那么用annotation方式的事务注解和bean配置,事务会失效,要将service bean配置到xml文件中才行 
     
    在主容器中(applicationContext.xml),将Controller的注解排除掉 
    <context:component-scan base-package="com.demo"> 
      <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> 
    </context:component-scan> 

    而在springMVC配置文件中将Service注解给去掉 
    <context:component-scan base-package="com.demo"> 
      <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> 
      <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" /> 
    </context:component-scan> 

    因为spring的context是父子容器,所以会产生冲突,Controller会先进行扫描装配,而此时的Service还没有进行事务的增强处理,得到的将是原样的Service(没有经过事务加强处理,故而没有事务处理能力) ,最后才是applicationContext.xml中的扫描配置进行事务处理

  • 相关阅读:
    一、用Delphi10.3模拟读取百度网页,并读取相关头部信息
    计算机语言发展史
    VMware workstation 14 安装 iOS虚拟机
    mysql-1
    linux网页资料链接
    Ubuntu常用命令大全
    搭建yum源
    CentOS7安装iptables防火墙
    nginx 第二课
    交换机
  • 原文地址:https://www.cnblogs.com/henuyuxiang/p/6674905.html
Copyright © 2011-2022 走看看