您的位置:首页 > 编程语言 > Java开发

spring 父子容器 事务管理

2016-04-04 15:31 363 查看
Spring容器优先加载由ServletContextListener(对应applicationContext.xml)产生的父容器,而SpringMVC(对应mvc_dispatcher_servlet.xml)产生的是子容器。子容器Controller进行扫描装配时装配的@Service注解的实例是没有经过事务加强处理,即没有事务处理能力的Service,而父容器进行初始化的Service是保证事务的增强处理能力的。如果不在子容器中将Service
exclude掉,此时得到的将是原样的无事务处理能力的Service。

改正:
1、applicationContext.xml:
    <context:component-scan base-package="com.will"/>

 
dispatcher.xml:

<context:component-scan base-package="com.will" >      

    <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
   


</context:component-scan>  

2、只用dispatcher.xml
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息