AOP를 이용한 트랜젝션 처리:한번에 처리 해야할 업무단위.
1.JDBC : Connection 객체/conn.commti(),conn.rollback()-> Service 
2. Mybaits : :SqlSession객체/ session.commit(),session.rollback() ->Service
3. Sprig : TransactionManager / 객체

 

사용위한 설정 : root-context.xml

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

붙인다....추가추가

사용할때 가장 중요한 것이 이부분이다. 여기가 정상기재시 일을 할수 있다...

 

이제 매니저 등록

<!-- 내가 트랜잭션 매니저다 선언 -->
	<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="dataSource"></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="Exception"/>
			<tx:method name="modify*" rollback-for="Exception"/>
			<tx:method name="remove*" rollback-for="Exception"/>
		</tx:attributes>
	</tx:advice> 
	<!-- 매니저를 aop에 적용 -->
	<aop:config proxy-target-class="true">
		<aop:pointcut expression="execution(* com.kh.junspring..*Impl.*(..))" id="serviceMethod"/>
		<!--com.kh.junspring패키지의 하위 클래스까지포함해 Impl로 끝나는 클래스의 모든매변변수 메소드에 적용  -->
		<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceMethod"/>
	</aop:config>
	</beans>

일부러 회원가입할때 한번 더 되도록 에러구문을 만들었다...

오늘 회원가입 엄청했다..일부러 에러 발생시켜 봤는데 에러메세지가 나와도 ROOT파일에 오타가 있다며 회원가입이 된다....그증거들..ㅋㅋㅋ

이후 오타 찾아내서 수정하니깐 에러메시지와함께 회원가입이 되지 않았다...

정리하면 앞서 잘 진행했던것도 EXCEPTION발생이 되면 자동으로 취소시켜 주는 것이다...ROLL-BACK.

'SPRING' 카테고리의 다른 글

JUNIT TEST 2-controller//  (0) 2022.11.10
LOG4j 등록  (0) 2022.10.11
예외처리 어노테이션  (0) 2022.10.07
AOP 심화 : 메소드 실행시간  (0) 2022.10.07
AOP 배우기  (0) 2022.10.07

+ Recent posts