将事物加在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" />
最后
以上就是悦耳麦片最近收集整理的关于springmvc 添加事物的全部内容,更多相关springmvc内容请搜索靠谱客的其他文章。
发表评论 取消回复