spring+springMVC+mybatis的事务无效。很尴尬! java
通过屡次尝试,原来是配置问题 ,固然前提你用的是spring 3.x与springmvc3.x.spring
通常application.xml是最早启动的,这时候如果全包扫描,须要排除掉@Controller的扫描,让它只扫描@Service,这样才能让他配置上代理事务。express
<context:component-scan base-package="com.chimy"> <!-- 排除@Controller --> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller"/> </context:component-scan>
在第二启动的spring-mvc.xml则须要排除掉@service注解,只让他扫描@Controller。spring-mvc
<context:component-scan base-package="com.chimy"> <!-- 排除@Service --> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service"/> </context:component-scan>
为什么会这样呢?由于在重复建立Bean时,会致使原有的代理失效 。原文档怎么描述的不太清楚!这个还须要查找缘由。。。mybatis