项目中的注解式事务配置不生效,在spring-mybatis文件中事务都已经配置好了可是就是不生效,最后发现是事务的加载顺序没有处理好,缘由以下:web
因为采用的是SpringMVC、 MyBatis,故统一采用了标注来声,明Service、Controller
因为服务器启动时的加载配置文件的顺序为web.xml---spring-mybatis.xml(Spring的配置文件)---servlet-mvc.xml(SpringMVC的配置文件),因为root-context.xml配置文件中Controller会先进行扫描装配,可是此时service尚未进行事务加强处理,获得的将是原样的Service(没有通过事务增强处理,故而没有事务处理能力),因此咱们必须在root-context.xml中不扫描Controllerspring
//spring-mybatis文件 <!-- 自动扫描组件,这里要把controler下面的 controller去除,他们是在spring3-servlet.xml中配置的,若是不去除会影响事务管理的。 --> <context:component-scan base-package="com.sence"> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Controller" /> </context:component-scan> //spring-mvc.xml文件 <!-- 扫描全部的controller 可是不扫描service--> <context:component-scan base-package="com.sence"> <context:include-filter type="annotation" expression="org.springframework.stereotype.Controller" /> <context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" /> </context:component-scan>