티스토리 뷰

context 추가.
context-transaction.xml 파일이 있다면 수정. 없다면 추가.
트랜잭션 처리 할 서비스 패키지 명을 넣어준다.

or execution(* egovframework.패키지명..*Service.*(..))

context-transaction.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
	xmlns:aop="http://www.springframework.org/schema/aop"
	xmlns:tx="http://www.springframework.org/schema/tx"
	xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
						http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-4.0.xsd
						http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-4.0.xsd">

	<bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
		<property name="dataSource" ref="egov.dataSource"/>
	</bean>
	  
	<tx:advice id="txAdvice" transaction-manager="txManager">
	   <tx:attributes>	 
	       <tx:method name="*" propagation="REQUIRED" rollback-for="Exception"/>
	   </tx:attributes>
	</tx:advice>
    
	<aop:config>
		<aop:pointcut id="requiredTx" expression="execution(* egovframework.com..*Impl.*(..)) or
				execution(* egovframework.rte.fdl.excel.impl.*Impl.*(..))
				or execution(* egovframework.패키지..*Service.*(..))
				"/>
		<aop:advisor advice-ref="txAdvice" pointcut-ref="requiredTx" />
	</aop:config>

</beans>

 

AbcService.java
@Transactional 어노테이션, throws Exception

@Transactional
public int testTran(Map m) throws Exception{
	int cnt = 0;
	cnt = testMapper.정상쿼리(m);
	cnt += testMapper.오류쿼리(m);
	return cnt;
}

 

AbcController.java

@RequestMapping("/test/testTran.do")
public String testTran(ModelMap model, HttpServletRequest request)  {
	String msgCode = "O";
	String msg = "";
	int result = 0;
	
	try {
		testService.testTran(Map);
	} catch (Exception e) {
		LOGGER.error("==오류 발생==");
		LOGGER.error(e.getMessage());
	}
	
	model.addAttribute("result", result);
	model.addAttribute("msgCode", msgCode);
	model.addAttribute("msg", msg);
	return "/test/testTran";
}
댓글
공지사항
최근에 올라온 글
최근에 달린 댓글
Total
Today
Yesterday
링크
«   2024/05   »
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 29 30 31
글 보관함