spring mvc 容器(spring mvc配置加载的servlet)从属于Context(ContextLoaderListener配置加载的spring上下文),如果同时配置了注解扫描,比如:

在spring-mvc.xml中如下:

   <context:component-scan base-package="com.xxx,com.yyy,com.zzz">

   <mvc:annotation-driven/>

在父容器中的spring-main.xml中:   

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

 如上,如果项目中存在某些service被2个容器同时扫描到,会促使这些service中声明式事务注解失效即使用@Transactional毫无作用。

  解决方法:

  在spring-mvc.xml中

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

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

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

</context:component-scan>

   如果2个容器配置的扫描没有冲突就没这么麻烦了。