송민준의 개발노트

transaction 본문

웹/Spring Framework

transaction

송민준 2020. 1. 3. 10:02

root-context.xml

<!-- 트랜잭션 처리 -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"></property>
	</bean>

 

servlet-context.xml

	<tx:advice id="txAdvice" transaction-manager="transactionManager">
		<tx:attributes>
			<tx:method name="*"/>
		</tx:attributes>
	</tx:advice>
	
	<aop:config>
		<aop:pointcut id="transactionPointcut"
			expression="execution(* com.naver.myhome5..*Impl.*Reply(..))"/>
		<aop:advisor advice-ref="txAdvice" pointcut-ref="transactionPointcut"/>
	</aop:config>

log4j.xml

	<root>
		<priority value="debug" />
		<appender-ref ref="console" />
	</root>

~ServiceImpl.java (에러 내는 곳)

double e= 1/0;

결과(sql처리를 2개를 하는데 1개 실행 후 에러가 나서 롤백을 시킴)

 

----------------------------------------annotation으로 깔끔하게 처리 가능--------------------------

servlet-context.xml

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

~ServiceImpl.java(에러 내는 곳)

@Override
	@Transactional
	public int boardReply(Board board) {
		boardReplyUpdate(board);
		double e= 1/0;
		board.setBOARD_RE_LEV(board.getBOARD_RE_LEV()+1);
		board.setBOARD_RE_SEQ(board.getBOARD_RE_SEQ()+1);
		return dao.boardReply(board);
	}

 

' > Spring Framework' 카테고리의 다른 글

Junit  (0) 2020.01.08
mybatis null값 처리  (0) 2020.01.08
AOP(Aspect Oriented Programming)  (0) 2020.01.02
email 서비스(네이버)  (2) 2019.12.31
404 에러, Exception 처리  (0) 2019.12.30