如果帶上事務,那么用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中的掃描配置進行事務處理