Spring中使用声明式事务
1.首先,配置事务代理
?
<!-- Transaction manager for a single Hibernate SessionFactory (alternative to JTA) --><bean id="hibernateTransactionManager"/><!-- Transactional proxy for the services --><bean id="baseTxProxy" lazy-init="true"/></property> <property name="transactionAttributes"><!-- 此处对需要使用事务管理的方法进行配置 --><props><prop key="updateFrequency">PROPAGATION_REQUIRED</prop><prop key="saveStaff">PROPAGATION_REQUIRED</prop><prop key="saveSchenulingDetailed">PROPAGATION_REQUIRED</prop><prop key="delSchenuling">PROPAGATION_REQUIRED</prop></props></property></bean>
?2.对需要事务管理的业务逻辑类配置事务代理
<!-- 班次管理 --><bean id="frequencyDAO" autowire="byName"/><bean id="wfmFrequencyEntity" autowire="byName" /> <!--需要被事务管理的类--> <bean id="frequencyService" autowire="byName" /> <!--配置业务逻辑类的事务代理--> <bean id="frequencyServiceTrans" parent="baseTxProxy"><property name="target"><ref local="frequencyService" /></property></bean> <!--让原来Action中的业务逻辑类指向事务代理类--><bean name="/frequencyAction" autowire="byName" ><property name="frequencyService" ref="frequencyServiceTrans" /></bean>
?
?
?