- Arawn's Dev Blog
- Outsider's Dev Story
- Toby's Epril
- Benelog
- NHN 개발자 블로그
- SK 플래닛 기술 블로그
- OLC CENTER
- 소프트웨어 경영/공학 블로그
- 모바일 컨버전스
- KOSR - Korea Operating System …
- 넥스트리 블로그
- 리버스코어 ReverseCore
- SLiPP
- 개발자를 위하여... (Nextree 임병인 수석)
- "트위터 부트스트랩: 디자이너도 놀라워할 매끈하고 직관…
- Learning English - The English…
- real-english.com
- 'DataScience/Deep Learning' 카테…
- Deep Learning Summer School, M…
- Deep Learning Courses
민서네집
spring 2.5 에서 transaction(트랜잭션) 걸기 본문
< Spring 2.5 >
트랜잭션이 안되서 한참 삽질을 한 결과
책이나 다른 웹에서도 알려주지 않았던 중요한 사실을 하나 알았는데...
<aop:config>
<aop:pointcut id="serviceOperation" expression="execution(* *..service.*.*(..))"/>
<aop:advisor advice-ref="txAdvice" pointcut-ref="serviceOperation"/>
</aop:config>
이 설정을 applicationContext.xml 파일에 만들었는데
aop를 적용할 빈이 있는 설정 파일(여기서는 service.xml) 에 두어야 한다.
< Spring 에서 AOP방식으로 Transaction 을 걸기 위해서는 다음의 라이브러리가 필요하다. >
spring-framework-2.5.6.SEC01-with-dependencies\spring-framework-2.5.6.SEC01\lib\aspectj
* aspectj/aspectjweaver.jar, aspectj/aspectjrt.jar, (aspectj/aspectjtools.jar)
- AspectJ 1.6.2 (http://www.aspectj.org)
- required for building the framework
- required at runtime when using Spring's AspectJ support
spring-framework-2.5.6.SEC01-with-dependencies\spring-framework-2.5.6.SEC01\lib\cglib
* cglib/cglib-nodep-2.1_3.jar
- CGLIB 2.1_3 with ObjectWeb ASM 1.5.3 (http://cglib.sourceforge.net)
- required for building the framework
- required at runtime when proxying full target classes via Spring AOP
이 라이브러리를 추가하지 않고서 WAS를 기동시켰을 때 에러가 나야지만 제대로 AOP 설정이 된 것이라고 볼 수 있다.
설정이 잘 못 되서 AOP가 인식안되면 처음 WAS 기동 시 에러가 나지 않음.
설정이 잘 되어 있는지 확인하는 방법
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="*" propagation="MANDATORY" rollback-for="Exception" />
</tx:attributes>
</tx:advice>
위와 같이 propagation="MANDATORY" 로 한번 걸어본다.
그러면 웹어플리케이션이 기동하고 나서 DB 접속 시 다음과 같이 에러가 나야 한다.
org.springframework.transaction.IllegalTransactionStateException: No existing transaction found for transaction marked with propagation 'mandatory'
at org.springframework.transaction.support.AbstractPlatformTransactionManager.getTransaction(AbstractPlatformTransactionManager.java:363)
at org.springframework.transaction.interceptor.TransactionAspectSupport.createTransactionIfNecessary(TransactionAspectSupport.java:263)
at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:101)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.interceptor.ExposeInvocationInterceptor.invoke(ExposeInvocationInterceptor.java:89)
at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:171)
at org.springframework.aop.framework.Cglib2AopProxy$DynamicAdvisedInterceptor.intercept(Cglib2AopProxy.java:635)
at webcalendar.signon.service.SignOnService$$EnhancerByCGLIB$$6bf581ad.verifyUser(<generated>)
at webcalendar.signon.controller.DBAuthenticator.authenticate(DBAuthenticator.java:33)
at webcalendar.signon.controller.LoginController.onSubmit(LoginController.java:47)
at org.springframework.web.servlet.mvc.SimpleFormController.processFormSubmission(SimpleFormController.java:267)
at org.springframework.web.servlet.mvc.AbstractFormController.handleRequestInternal(AbstractFormController.java:265)
at org.springframework.web.servlet.mvc.AbstractController.handleRequest(AbstractController.java:153)
at org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.handle(SimpleControllerHandlerAdapter.java:48)
at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:875)
at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:807)
at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:571)
at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:511)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:637)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.springframework.web.filter.CharacterENCODINGFilter.doFilterInternal(CharacterENCODINGFilter.java:96)
at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:76)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:298)
at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:852)
at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:588)
at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:489)
at java.lang.Thread.run(Thread.java:595)
'Spring' 카테고리의 다른 글
OSGi & SpringDM 책 예제소스 (0) | 2013.01.12 |
---|---|
1. Equinox 기반 OSGi 번들 만들기 (0) | 2013.01.12 |
KSGU 제13회 세미나와 발표 동영상 (0) | 2013.01.10 |
[SpringMVC] RequestMapping 의 전략 (0) | 2012.08.23 |
java 애노테이션 가져오기 (0) | 2012.08.23 |