Spring Mvc Spring Mybatis 全注解事物配置,Service层事物不回滚

spring-context.xml中,配置不扫描Coontroller
	<!-- 使用Annotation自动注册Bean,解决事物失效问题:在主容器中不扫描@Controller注解,在SpringMvc中只扫描@Controller注解。 -->
	<context:component-scan base-package="com.pds.j2ee"><!-- base-package 
			如果多个,用“,”分隔 -->
		<context:exclude-filter type="annotation"
			expression="org.springframework.stereotype.Controller" />
	</context:component-scan>
Spring-mvc.xml中,配置只扫描Controller
	<!-- 使用Annotation自动注册Bean,只扫描@Controller -->
	<context:component-scan base-package="com.pds.j2ee" use-default-filters="false"><!-- base-package 如果多个,用“,”分隔 -->
		<context:include-filter type="annotation" expression="org.springframework.stereotype.Controller"/>
	</context:component-scan>
PS:另需注意,如果配置文件中配置了多个事物,需在Service层 注解事物时指定事物的名称
@Transactional("transactionManager3")
Service层方法体重 不可以使用 try catch 快,否则事物不会回滚,需要 throws Exception

猜你喜欢

转载自haoyiming.iteye.com/blog/2392835