트랜잭션은 xml설정만 사용할 수 있다.      // logging은 어노테이션을 써도 된다.

 

Namespace에서 aop, tx를 사용한다.

DataSourceTransactionManager 클래스를 이용한다.     // Mybatis, JPA를 이용할 땐 트랜잭션 관리자를 변경해주면 된다.

이 클래스를 <bean>에 등록한 뒤, <tx:advice>라는 어드바이스 관리 엘리먼트를 사용한다.

 

<tx:advice id="txadvice" transaction-manager="txManager">
	<tx:attributes>
    	<tx:method name="get*" read-only="true"/>
        <tx:method name="*"/>
    </tx:attributes>
</tx:advice>
// read-only(앞에 get이 붙는 함수만 tx처리 예외),no-roolback-for(롤백 안할 예외 지정), 
// rollback-for(롤백할 예외지정)

 

aop 설정할 땐 <aop:advisor>를 사용한다.

<aop:config>
	<aop:pointcut id="txPointcut" ~~~~ />
    <aop:advisor pointcut-ref="txPointcut" advice-ref="txAdvice"/>
</aop:config>
// advice-ref는 advice의 id속성

 

 

정상 실행시 commit(), 문제 발생시 rollback()

tx는 함수 단위로 관리되므로 함수안에 예외가 하나라도 있으면 rollback() 된다.

'Spring' 카테고리의 다른 글

Spring ) Eclipse java.lang.ClassNotFoundException : org.spring.framework.web.context.ContextLoaderListener 해결법  (0) 2022.06.28
Spring ) 객체 생성  (0) 2022.06.03
Spring ) AOP  (0) 2022.06.03
Spring ) Validate  (0) 2022.05.30
Spring ) JPA  (0) 2022.05.30

+ Recent posts