
版权声明:本文为博主原创文章,未经博主允许不得转载。
1.将事物加在contrller层,只需要在springmvc.xml中加上<tx:annotation-driven/>即可,并且contrller类中加上@Transactional即可。
前提是在spring.xml中要有事物管理器的配置即
<!-- 事务配置 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
2.将事物加在service层,需要在springmvc.xml中加上 <context:component-scan base-package="com.bj.wsl">
<context:exclude-filter type="annotation" expression="org.springframework.stereotype.Service" />
</context:component-scan>这句话,在spring.xml中加上 <context:component-scan base-package="com.bj.wsl">
</context:component-scan>,并且service类中加上@Transactional即可。
前提是在spring.xml中要有事物管理器的配置即
<!-- 事务配置 -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource" />
</bean>
<!-- 使用annotation注解方式配置事务 -->
<tx:annotation-driven transaction-manager="transactionManager" />
这是我具体实施时参照的url:
http://blog.csdn.net/will_awoke/article/details/12002705
http://5880861.blog.51cto.com/5870861/1544168/