Programing/egovFramework

이중화된 Oracle DB에 접속 하기위한 설정, 멀티 DB 접속

리커니 2015. 11. 23.
반응형

 

이중화된 Oracle DB에 접속 하기위한 설정, 멀티 DB 접속

 

개발을 하다보면 서버를 이중화 해서 사용할 때가 있다.

이런 이중화된 DB에 접속 하는 방법에 대해서 알아보자.

 

[spring - context-transaction.xml]

 

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
32
33
34
35
36
37
38
39
<?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:tx="http://www.springframework.org/schema/tx" xmlns:util="http://www.springframework.org/schema/util"
 xmlns:aop="http://www.springframework.org/schema/aop"
 xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.1.xsd
      http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.1.xsd
      http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-3.1.xsd
      http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.1.xsd">
      
 
<!-- contextProperties를 읽어온다 -->
 <util:properties id="contextProperties" location="classpath:context.properties"/>
   
 
<!-- contextProperties에서  db접속 정보를 가져온다. -->
 <bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
  <property name="driverClassName" value="#{contextProperties.driver}"/>
  <property name="url" value="#{contextProperties.url}"/>
  <property name="username" value="#{contextProperties.username}"/>
  <property name="password" value="#{contextProperties.password}"/>
 </bean>
 
 <bean id="txManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
  <property name="dataSource" ref="dataSource"/>
 </bean>
 
 <tx:annotation-driven transaction-manager="txManager" />
 
 <tx:advice id="txAdvice" transaction-manager="txManager">
  <tx:attributes>
   <tx:method name="*" rollback-for="Exception" propagation="REQUIRED"/>
  </tx:attributes>
 </tx:advice>
    
 <aop:config>
  <!-- <aop:pointcut id="serviceRequiredTx" expression="execution(* uits..ServiceImpl.*(..))"/>
  <aop:advisor advice-ref="txAdvice" order="2" pointcut-ref="serviceRequiredTx" /> -->
 </aop:config> 
</beans>
cs

 

 

[context.properties] 파일의 위치는 src 바로 아래이다.

 

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
driver=oracle.jdbc.driver.OracleDriver
url=jdbc:oracle:thin:@(DESCRIPTION =\
    (ADDRESS_LIST =\
      (ADDRESS = (PROTOCOL = TCP)(HOST = 첫번째DB주소)(PORT = 포트번호))\
      (ADDRESS = (PROTOCOL = TCP)(HOST = 두번째DB주소)(PORT = 포트번호))\
      (LOAD_BALANCE = ON)\
      (FAILOVER = ON)\
    )\
    (CONNECT_DATA =\
      (SERVER = DEDICATED)\
      (SERVICE_NAME = DB의SID)\
      (FAILOVER_MODE =\
        (TYPE = SELECT)\
        (METHOD = BASIC)\
        (RETRIES = 20)\
        (DELAY = 3)\
      )\
    )\
  )
username=유저명
password=패스워드
cs

 

반응형

댓글

💲 추천 글