@Transactional
Spring에서 제공하는 선언적 트랜잭션 관리를 위한 어노테이션이다. 명시적으로 트랜잭션의 시작, 커밋, 롤백 등을 호출하지 않고도 데이터 액세스 로직에 트랜잭션을 적용할 수 있다.
선언적 트랜잭션 사용법
XML 설정
<!-- enable the configuration of transactional behavior based on annotations -->
<!-- a TransactionManager is still required -->
<tx:annotation-driven transaction-manager="txManager"/>
<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<!-- (this dependency is defined somewhere else) -->
<property name="dataSource" ref="dataSource"/>
</bean>
어노테이션 설정
@Transactional
public class DefaultFooService implements FooService {
@Override
public Publisher<Foo> getFoo(String fooName) {
// ...
}
// ...
}
- 클래스나 메서드 단위로 적용할 수 있다.
'Spring 단기심화 2기' 카테고리의 다른 글
TIL_OSIV_241129 (0) | 2024.11.29 |
---|---|
TIL_AOP_241126 (0) | 2024.11.26 |
TIL_Docker-241124 (0) | 2024.11.24 |
TIL_저장 프로시저_241123 (1) | 2024.11.23 |
TIL_Transaction_241122 (0) | 2024.11.22 |