관리 메뉴

버리야 날자

[iBATIS] 7. iBATIS + Spring + transaction 본문

나만의 작업/iBatis

[iBATIS] 7. iBATIS + Spring + transaction

버리 버리야 2008.09.02 10:03

7. iBATIS + Spring + transaction

1. 코드   기반의   트랜잭션   처리 (Progrmmatic Transaction)

2. 선언적   트랜잭션 (Declarative Transaction)  

- <tx:advice> 태그를   이용  

- TransactionProxyFactoryBean 태그를   이용  

- @Transactional 어노테이션을   이용


<tx:advice> 태그 이용

<beans xmlns="http://www.springframework.org/schema/beans"

       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"

       xmlns:aop="http://www.springframework.org/schema/aop"

       xmlns:tx="http://www.springframework.org/schema/tx"

       xsi:schemaLocation="

       http://www.springframework.org/schema/beans

http://www.springframework.org/schema/beans/spring-beans-2.0.xsd

       http://www.springframework.org/schema/tx

       http://www.springframework.org/schema/tx/spring-tx-2.0.xsd

       http://www.springframework.org/schema/aop

       http://www.springframework.org/schema/aop/spring-aop-2.0.xsd">

  

  <bean id="fooService" class="x.y.service.DefaultFooService"/>

  <tx:advice id="txAdvice" transaction-manager="txManager">  

      <tx:method name="get*" read-only="true"/>

      <tx:method name="*"/>

 

<aop:pointcut id="fooServiceOperation" expression="execution(* x.y.service.FooService.*(..))"/>

<aop:advisor advice-ref="txAdvice" pointcut-ref="fooServiceOperation"/>

 

@ Transactional 어노테이션을   이용

@Transactional(readOnly = true)

public class DefaultFooService implements FooService {

  public Foo getFoo(String fooName) {

    // do something

  }

  // these settings have precedence for this method

  @Transactional(readOnly = false, propagation = Propagation.REQUIRES_NEW)

  public void updateFoo(Foo foo) {

    // do something

  }

}


<bean id="fooService" class="x.y.service.DefaultFooService"/>

<tx:annotation-driven transaction-manager="txManager"/>





0 Comments
댓글쓰기 폼