SpringMVC+MyBatis聲明式事務治理。本站提示廣大學習愛好者:(SpringMVC+MyBatis聲明式事務治理)文章只能為提供參考,不一定能成為您想要的結果。以下是SpringMVC+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> <!-- 主動掃描組件,這裡要把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>在servlet-context.xml中掃描Controller同時不掃描Service,設置裝備擺設以下:
<!-- 掃描一切的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> <!-- 掃描一切的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>上面便可以停止設置裝備擺設聲明式事務治理了,設置裝備擺設以下:
<!-- transaction manager, use DataSourceTransactionManager --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- spring declarative transaction management --> <aop:config> <aop:pointcut id="fooServiceMethods" expression="execution(* com.sence.*.service.impl.*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceMethods"/> </aop:config> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="find*" read-only="true"/> <tx:method name="load*" read-only="true"/> <tx:method name="*" rollback-for="CustomException"/> </tx:attributes> </tx:advice> <!-- transaction manager, use DataSourceTransactionManager --> <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> <property name="dataSource" ref="dataSource" /> </bean> <!-- spring declarative transaction management --> <aop:config> <aop:pointcut id="fooServiceMethods" expression="execution(* com.sence.*.service.impl.*.*(..))"/> <aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceMethods"/> </aop:config> <tx:advice id="txAdvice" transaction-manager="txManager"> <tx:attributes> <tx:method name="find*" read-only="true"/> <tx:method name="load*" read-only="true"/> <tx:method name="*" rollback-for="CustomException"/> </tx:attributes> </tx:advice>到此我的設置裝備擺設完成了,然則經由我的測試,當我往MySQL數據庫表批量增長對象時,當個中一個對象湧現毛病,拋出CustomException事務卻不回滾,這個真是使人頭疼,因而我持續查找,步調以下: 1. 查找能否聲明式事務治理有誤,如切入點寫錯了