<스프링 트랜잭션 사용>
빈 설정 및 주입
< bean id =“transactionManager”
class=“org.springframework.jdbc.datasource.DataSourceTransactionManager”>
< property name=“dataSource” ref=“dataSource” />
@Autowired
PlatformTransactionManager transactionManager;
commit, rollback
TransactionStatus status = transactionManager.getTransaction(new
DefaultTransactionDefinition());
transactionManager.commit(status);
transactionManager.rollback(status)
빈 설정
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name=“메소드명" propagation="REQUIRED" />
</tx:attributes>
</tx:advice>
<aop:config>
<aop:pointcut expression="execution( public spring.Service.*(..) )"
id="firstTransactionMethod" />
<aop:advisor advice-ref="txAdvice" pointcut-ref="firstTransactionMethod" />
</aop:config>
※ <tx:advice> 태그는 트랜잭션 적용을 위해 AOP를 통해 이루어진다.
빈 설정
<tx:annotation-driven transaction-manager="transactionManager”/>
어노테이션 설정
@Transaction(rollbackFor=Exception.class)