zoukankan      html  css  js  c++  java
  • SpringMVC + Spring + MyBatis 学习笔记:SpringMVC和Spring一同工作的时候,AOP事务管理不起作用的解决方法

    系统:WIN8.1

    数据库:Oracle 11GR2

    开发工具:MyEclipse 8.6

    框架:Spring3.2.9、SpringMVC3.2.9、MyBatis3.2.8


    SpringMVC 的 springmvc.xml文件中 配置扫描包,不要包含 service的注解,Spring 的 配置文件配置包扫描时,不要包含controller的注解,如下所示:

    Spring MVC的配置文件:

    <context:component-scan base-package="包路径">
    
      <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/>
    
    </context:component-scan> 

    Spring 的配置文件:

    1 <context:component-scan base-package="包路径">           
    2 
    3  <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
    4 
    5 </context:component-scan>

    Spring MVC启动时的配置文件,包含组件扫描、url映射以及设置freemarker参数,让spring不扫描带有@Service注解的类。

    Why?

    因为 springmvc.xml 与 applicationContext.xml 不是同时加载,如果不进行这样的设置,那么 Spring就会将所有带@Service注解的类都扫描到容器中,等到加载 applicationContext.xml的时候,会因为容器已经存在Service类,使得cglib将不对Service进行代理,直接导致的结果就是在 applicationContext 中的事务配置不起作用,发生异常时,无法对数据进行回滚。

  • 相关阅读:
    sqlchemy self made
    scrapy 自定义图片路径保存,并存到数据库中
    关于scrapy下载文件重命名的办法以及对应url没有文件后缀的办法
    下载转码
    scrapy 下载图片 from cuiqingcai
    Scrapy框架学习
    字符串处理
    scrapy 日志处理
    sqlalchemy多对多查询
    sqlalchemy 多对多关系
  • 原文地址:https://www.cnblogs.com/morlin/p/4383599.html
Copyright © 2011-2022 走看看