multi DB 문제(Spring + Mybatis)

1,665 views
Skip to first unread message

정대현

unread,
Feb 2, 2015, 7:12:21 PM2/2/15
to ks...@googlegroups.com
안녕하세요.

멀티 DB 연결 문제 때문에 고민이 많이 생겨서 도움을 요청 하고자 합니다.
한 3일째 해메고 있는데 예제 소스라도 받아서 제것이랑 비교 하고 싶습니다.

하나 고치면 이쪽 저쪽에서 에러가 나와서 무엇이 문제 인지 모르겠습니다. ㅠㅠ


혹시라도 몰라서 제 소스를 첨부 하였습니다.
ㅠㅠ

이렇게 질문을 드려서 죄송합니다.

FrameWork.zip
Message has been deleted

정대현

unread,
Feb 3, 2015, 8:04:44 PM2/3/15
to ks...@googlegroups.com

종희님꺼로 해 보았으나 안되더라구요.
답변을 달아 주셔서 감사합니다.


제가 이것 저젓 수정해서 연결은 되었으나 transaction은 되지 않고 있습니다.

controller에서 익센션 발생시(또는 throw일때 )rollback을 하고자 하는데 되지 않고 있습니다.

XML설정 과 controller은 아래와 같습니다. 

최종적으로 bbb갑 입력이 되지 않아야 되는데 해당 부분을 어떻게 해야 할지 감이 잡히지 않고 있습니다.
답이 아니라도 좋으니 참고 또는 공부 할만한 사이트를 알려 주시면 감사하겠습니다.

이번에도 소스도 같이 첨부 합니다.

    <?xml version="1.0" encoding="UTF-8"?>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
<property name="locations">
<value>/WEB-INF/spring/appServlet/dbpool.properties</value>
</property>
</bean>
<bean id="dataSoruce" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
<property name="driverClassName" value="${write.jdbc.driverClass}" />
<property name="url" value="${write.jdbc.url}" />
<property name="username" value="${write.jdbc.username}" />
<property name="password" value="${write.jdbc.password}" />
<property name="initialSize" value="${write.jdbc.min.size}" />
<property name="maxActive" value="${write.jdbc.max.size}" />
<property name="maxIdle" value="5" />
<property name="minIdle" value="2" />
<property name="validationQuery" value="select 1"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="7200000"/>
</bean>
<!--   Transaction Manager -->
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
  <property name="dataSource" ref="dataSoruce" />
  </bean>
  
<aop:config proxy-target-class="true">
  <aop:pointcut id="serviceOperation" expression="execution(* com.ys2cdh.framework.dao.service.*Service.*(..))" />
<aop:advisor id="transactionAdvisor" pointcut-ref="serviceOperation" advice-ref="txAdvice"/>
</aop:config>
<tx:advice id="txAdvice" transaction-manager="transactionManager">
<tx:attributes>
<tx:method name="insert*" rollback-for="Exception"/>
<tx:method name="update*" rollback-for="Exception"/>
<tx:method name="remove*" rollback-for="Exception"/>
</tx:attributes>
</tx:advice>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSoruce" />
<property name="configLocation" value="classpath:/com/ys2cdh/framework/mybatis/mybatisWrite-config.xml" />
</bean>

<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="clearCache">
<constructor-arg index="0" ref="sqlSessionFactory" />
</bean>
<!-- 
<bean id="writeMapper" class="org.mybatis.spring.mapper.MapperFactoryBean"> 
   <property name="mapperInterface" value="com.ys2cdh.framework.dao.service.PersonWriteMapper" />
   <property name="sqlSessionFactory" ref="sqlSessionWriteFactory" /> 
   <property name="sqlSessionTemplate" ref="sqlSessionWriteTemplate" /> 
</bean>
     -->
     
     
<bean id="readSource" class="org.apache.tomcat.jdbc.pool.DataSource" destroy-method="close">
<property name="driverClassName" value="${read.jdbc.driverClass}" />
<property name="url" value="${read.jdbc.url}" />
<property name="username" value="${read.jdbc.username}" />
<property name="password" value="${read.jdbc.password}" />
<property name="initialSize" value="${read.jdbc.min.size}" />
<property name="maxActive" value="${read.jdbc.max.size}" />
<property name="maxIdle" value="5" />
<property name="minIdle" value="2" />
<property name="validationQuery" value="select 1"/>
<property name="testWhileIdle" value="true"/>
<property name="timeBetweenEvictionRunsMillis" value="7200000"/>
</bean>
<!--   Transaction Manager 
<bean id="transactionReadManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager"> 
  <property name="dataSource" ref="readSource" />
  </bean>
  -->
  <bean id="sqlSessionReadFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="readSource" />
<property name="configLocation" value="classpath:/com/ys2cdh/framework/mybatis/mybatisRead-config.xml" />
</bean>

<bean id="sqlSessionRead" class="org.mybatis.spring.SqlSessionTemplate" destroy-method="clearCache">
<constructor-arg index="0" ref="sqlSessionReadFactory" />
</bean>
</beans>

------------------------------------------------------------------------------------------------------------------
controller

@RequestMapping(value = "/insert", method = RequestMethod.GET)
public ModelAndView insert(HttpServletRequest request)
{

// HttpServletRequest를 이용하여 main.jsp로부터 값을 가져온다 getParameter로는 id값을 가져옴.
Person person = new Person();
person.setId((String) request.getParameter("id"));
person.setNamem("bbbb");

personWriteServiceImpl.insertperson(person);
try
{
throw new Exception("test");
}
catch (Exception e)
{
// TODO Auto-generated catch block
e.printStackTrace();
}

// 아래부분은 select값을 result.jsp파일에 보여주기 위해 또사용.
ModelAndView result = new ModelAndView();
List<Person> memberList = personReadServiceImpl.selectPerson();

result.addObject("result", memberList);
result.setViewName("result");
return result;
}
FrameWork.zip

김종희

unread,
Feb 3, 2015, 8:16:14 PM2/3/15
to ks...@googlegroups.com

mybatis버전이 몇인지...

참고로 제가 사용하는 버전입니다.
<!--  my batis setting -->
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.2.7</version>
        </dependency>
        <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis-spring</artifactId>
            <version>1.2.2</version>
        </dependency>
<dependency>
<groupId>cglib</groupId>
<artifactId>cglib-nodep</artifactId>
<version>3.1</version>
</dependency> 


그럼 수고하세요~




2015. 2. 4., 오전 10:04, 정대현 <ys2...@gmail.com> 작성:

--
이 메일은 Google 그룹스 'Korea Spring User Group Q&A' 그룹에 가입한 분들에게 전송되는 메시지입니다.
이 그룹에서 탈퇴하고 더 이상 이메일을 받지 않으려면 ksug+uns...@googlegroups.com에 이메일을 보내세요.
http://groups.google.com/group/ksug에서 이 그룹을 방문하세요.
웹에서 이 토론을 보려면 https://groups.google.com/d/msgid/ksug/fc9af19b-a4d4-4799-a067-c154ec2762af%40googlegroups.com을(를) 방문하세요.
더 많은 옵션을 보려면 https://groups.google.com/d/optout을(를) 방문하세요.
<FrameWork.zip>

신재근

unread,
Feb 3, 2015, 9:12:02 PM2/3/15
to ks...@googlegroups.com

Service 패키지 안에 있는 것만 롤백될텐데~

<aop:config proxy-target-class="true">
   <aop:pointcut id="serviceOperation" expression="execution(* com.ys2cdh.framework.dao.service.*Service.*(..))" />
<aop:advisor id="transactionAdvisor" pointcut-ref="serviceOperation" advice-ref="txAdvice"/>
</aop:config>

컨트롤러 계층은 어떤 패키지에 있는지 잘 모르겠지만
Service 패키지 안에 있나요?

그럼 되야 하는게 맞을텐데 ㅠㅜ



2015년 2월 4일 오전 10:16, 김종희 <kimp...@gmail.com>님이 작성:
웹에서 이 토론을 보려면 https://groups.google.com/d/msgid/ksug/F1BFD6A1-CCF8-48A8-9FE1-C12297061FDF%40gmail.com을(를) 방문하세요.

BeomJun Park

unread,
Feb 4, 2015, 4:09:02 AM2/4/15
to ks...@googlegroups.com
혹시 디비 엔진이 myisam 아니에요?

2015년 2월 4일 오전 11:11, 신재근 <fre...@gmail.com>님이 작성:

포데브

unread,
Feb 4, 2015, 8:04:49 AM2/4/15
to ks...@googlegroups.com
먼저 모바일로 글을 쓰는거라 예제소스를 작성하지 못한점 양해부탁드립니다.
일단 멀티디비 연결은 해결하셨다니 넘어가고 트랜잭션 부분에 대해서 조언을 드리겠습니다.
로컬트랜잭션매니저나 데이터소스트랜잭션매니저는 분산트랜잭션을 지원하지 않습니다. 즉 2PC(2 Phase Commit)를 지원하기 위해서는 XA 드라이버를 사용하고 JTA트랜잭션매니저를 사용해야만 합니다. 다만 상용WAS를 사용하고 계시거나 JBoss와 같이 EJB컨테이너를 갖는 WAS에서는 LLR 또는 LRCO 같은 개념의 기능을 제공하고 있어서 non-XA드라이버로도 2PC를 지원하게끔 설정할수 있습니다.
WAS의 JTA를 사용할 수 없는 상황이라면 JOTM이나 Atomikos 또는 jbossts 같은 것을 사용하고 XA드라이버를 JTA트랜잭션매니저로 사용하시면 멀티디비 에서 트랜잭션을 묶을 수 있습니다. 설정이 어렵기는 하지만 불가능하지는 않습니다.
테스트케이스는 XA를 사용해도 되지만 성능이슈가 있으므로 좋은(?)WAS를 사용하고 계시다면 LLR 또는 LRCO 사용을 적극 추천합니다. 이전의 non-XA 에뮬레이션 기능과 유사하나 성능이 극적으로 개선된것이라서 추천할만 합니다.
참고고 JOTM JTA 키워드로 검색하시면 분산크랜잭션 관련 자료를 많이 찾아볼수 있습니다.

포데브

unread,
Feb 4, 2015, 8:07:48 AM2/4/15
to ks...@googlegroups.com
Reply all
Reply to author
Forward
0 new messages