spring+springMvc+mybatis

1.spring+springMvc+mybatis配置事物的控制,只需要在application.xml中添加

 

 

<bean id="transManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"></property>
	</bean>
<tx:annotation-driven transaction-manager="transManager"/>

 本以为很快就搞定,测试了下。出现异常时事物没有滚,在网上找了很多资料,说的是切面类生成的不是代理的类,并且调用的类也必须是代理类。但是为什么我注解的@service不是代理类呢?一直很疑问,最后看到一篇帖子终于找到了结果。

 

问题出在springMvc配置文件

 

 

原文件配置:

 

<context:component-scan base-package="com.tongli.cn2401,com.tongli.manage">

 修改后配置:

<context:component-scan base-package="com.tongli.cn2401,com.tongli.manage">
		<context:exclude-filter type="annotation"  
            expression="org.springframework.stereotype.Service"/>
	</context:component-scan>

 

 

 重启后,事物控制起作用了,抛出异常事物会回滚。

 

问题的原因是:mvc配置文件启动时,service注解也被扫描了。然后加载application配置文件时service类已经生成了,使得cglib不会对service进行代理

 

 

链接地址:http://blog.csdn.net/jaedong4j/article/details/51087576

 

 

猜你喜欢

转载自hejw-001.iteye.com/blog/2384520