Notice
Recent Posts
Recent Comments
Link
일 | 월 | 화 | 수 | 목 | 금 | 토 |
---|---|---|---|---|---|---|
1 | ||||||
2 | 3 | 4 | 5 | 6 | 7 | 8 |
9 | 10 | 11 | 12 | 13 | 14 | 15 |
16 | 17 | 18 | 19 | 20 | 21 | 22 |
23 | 24 | 25 | 26 | 27 | 28 |
Tags
- app.use
- 추상클래스
- 생성자
- 자바스크립트
- push함수
- 배열
- 삼항연산자
- mybatis
- git
- 오류
- java
- int와 integer
- Node.js
- dart
- 깃허브
- Pug
- DB
- qqOperater
- 자바
- React
- 네임드생성자
- js
- 코딩테스트
- 다형성
- 콘솔게임
- Oracle
- 리액트
- Spring
- Sort()
- Middleware
Archives
- Today
- Total
평행코드
<Spring> 트랜잭션처리하기 본문
spring이 제공하는 TransactionManager클래스를 이용
→ DML 구문을 실행하면 기본적으로 commit(); 처리를 함
→ 같은 세션에서 DML구문을 실행할때 RuntimeException이 발생을 하면 rollback(); 처리
트랜잭션설정하기
springconfigutation.xml에 txnamespace를 등록,
트랜잭션매니저를 bean으로 등록,
root-context.xml
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:aop="http://www.springframework.org/schema/aop"
xsi:schemaLocation="http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/aop https://www.springframework.org/schema/aop/spring-aop-4.3.xsd
http://www.springframework.org/schema/tx https://www.springframework.org/schema/tx/spring-tx-4.3.xsd">
</beans>
<!-- 트랜잭션처리 bean등록하기 -->
<bean id="transactionManager"
class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="proxyDataSource"/>
</bean>
<!-- 어노테이션방식으로 트랜잭션처리하기 -->
<tx:annotation-driven transaction-manager="transactionManager"/>
- 어노테이션방식
- 적용할 메소드의 선언부에 @Transational
- @Transactional(옵션설정)
- AOP방식을 이용해서 처리하기 때문에 AOP설정이 되어있어야함
- xml 방식
- tx:config 태그로 트랜잭션에 대한 설정
- aop:config 태그로 적용할 메소드를 설정
트랜잭션 옵션설정
- propagation : 트랜잭션을 생성하는 방법에 대한 설정 default 이미 시작된 트랜잭션이 있으면 참여, 없으면 트랜잭션 생성
- isolation : 트랜잭션에서 수정된 내용을 다른 트랜잭션에서 사용할 수 있는지 여부
- timeout
- read-only : select문에 사용
- rollback-for, rollbackfor : rollback을 처리할 기준(Exception)
- no-rollback-for
'Spring' 카테고리의 다른 글
<Spring> Security (0) | 2023.12.14 |
---|---|
<Spring> AOP (Aspect Orientied Programing) (0) | 2023.12.13 |
<Spring> 인터셉터(Interceptor) (0) | 2023.12.11 |
<Spring> bean validator 구현하는 방법 (1) | 2023.12.11 |
<Spring> 로그 남기기 (2) | 2023.12.11 |