82. AOP를 이용한 트랜잭션 처리

hanahana·2022년 10월 11일
0

Spring 학원수강

목록 보기
40/45
post-thumbnail
  1. JDBC: Connection 객체 / conn.commit(), conn.rollback() → Service
  2. Mybatis :SqlSessio 객체/ session.commit(), session.rollback()→Service
  3. Spring : TransactionManager 객체

transaction 처리

  • db에 명령어를 입력하고 commit이나 rollback으로 명령을 끝내야 한다.
  • 지금까지는store에
    int result = session.insert(”이름.아이디”,입력할 값);
    session.insert(”이름.아이디”,입력값);
    - 이었을때 둘중 하나만 성공했다면 성공한것만 commit 실패한것은 rollback을 했다
  • 하지만 트랜지션처리를 하면 둘중에 하나만 성공하면 모든 명령어를 rollback한다

트랜잭션 처리 하는 법

main - src - spring - root-context.xml

<!--<beans>안에 넣는다-->
<bean id="transactionManager"
		class="org.springframework.jdbc.datasource.DataSourceTransactionManager
">
		<property name="dataSource" ref="dataSource"> 
<!--접속정보 저장된 name-->

		</property>

	</bean>
<!-- 트랜잭션 XML 방식 -->
	<tx:advice id="txAdvice"
		transaction-manager="transactionManager">
		<tx:attributes>

			<tx:method name="print*" read-only="true" />
			<tx:method name="register*" rollback-for="Exeption" />
			<tx:method name="modify*" rollback-for="Exeption" />
			<tx:method name="remove*" rollback-for="Exeption" />
		</tx:attributes>
	</tx:advice>

	<aop:config proxy-target-class="true">
		<aop:pointcut
			expression="execution(* com.kh.junspring..*Impl.*(..))"	id="serviceMethod" />
		<aop:advisor advice-ref="txAdvice"
			pointcut-ref="serviceMethod" />
	</aop:config>
profile
hello world

0개의 댓글