1.更改注解
@Autowired
private JdbcTemplate jdbcTemplate;
换成
private JdbcTemplate jdbcTemplate;
public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
this.jdbcTemplate = jdbcTemplate;
}
2.SpringXML.xml
之前的C3P0和 JdbcTemplate设置保存不变
<!-- 1配置bean-->
<bean id="BookShopDao" class="SpringTemplate.SpringXML事务.SpringTX事务准备.BookShopDaoImpl">
<property name="jdbcTemplate" ref="JdbcTemplate"/>
</bean>
<bean id="BookShopService" class="SpringTemplate.SpringXML事务.SpringTX事务准备.service.BookShopServiceImpl">
<property name="bookShopDao" ref="BookShopDao"/>
</bean>
<bean id="cashier" class="SpringTemplate.SpringXML事务.SpringTX事务准备.service.CashierImpl">
<property name="bookShopService" ref="BookShopService"/>
</bean>
<!-- 2配置事务管理器-->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource"/>
</bean>
<!-- 3配置 事务属性-->
<tx:advice id = "txAdvice" transaction-manager="transactionManager" >
<tx:attributes>
<tx:method name="purchase" propagation="REQUIRES_NEW" />
<tx:method name="*"/>
</tx:attributes>
</tx:advice>
<!--4.配置事务切点 以及把事务切入点和事务属性关联-->
<aop:config>
<aop:pointcut id="txPointCut"
expression="execution(* SpringTemplate.SpringXML事务.SpringTX事务准备.service.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="txPointCut"></aop:advisor>
</aop:config>
之前@Transactional()注解的方式修改propagation等属性可以直接
<tx:method name="purchase" propagation="REQUIRES_NEW" />
前提是切入点中的包含了这个方法
<aop:pointcut id="txPointCut"
expression="execution(* SpringTemplate.SpringXML事务.SpringTX事务准备.service.*.*(..))"/>
未使用这个之前 事务为同一事务,执行要么全做要么全不做
执行了这个之后可以在 大事务中的小事务每个执行