multi

[EgovFramework] ์ „์ž์ •๋ถ€ํ”„๋ ˆ์ž„์›Œํฌ multi DB ์„ค์ •

natrue 2020. 8. 27. 14:52
728x90

multi DB ์—ฐ๊ฒฐํ•˜๋Š”๊ฒŒ ์–ด๋ ต์ง„ ์•Š์ง€๋งŒ

๋‚˜์ฒ˜๋Ÿผ ์–ด์ฒ˜๊ตฌ๋‹ˆ ์—†๋Š” ์ด์œ ๋กœ

์˜ค๋ž˜ ์žก๊ณ  ์žˆ์„ ์ˆ˜๋„..  หƒฬฃฬฃฬฃฬฃฬฃฬฃ๏ธฟห‚ฬฃฬฃฬฃฬฃฬฃฬฃ 

 

๋„์›€์ด ๋˜๊ธธ ๋ฐ”๋ผ๋ฉฐ ์ ๋Š” ๊ธ€ 

 

 

 

 

1.  context-datasouse.xml ์„ค์ •ํ•˜๊ธฐ 

 

 

tibero db๋ฅผ ์“ฐ๋˜ ํ”„๋กœ์ ํŠธ์—

 

mssql db๋ฅผ ๋ฉ€ํ‹ฐ๋กœ 

ํ•จ๊ป˜ ์‚ฌ์šฉํ•ด์•ผํ•ด์„œ 

 

mssql bean์„

context-datasourse.xml์— ์ถ”๊ฐ€ํ•ด์ฃผ๊ธฐ 

	<!-- MSSQL -->
    <bean id="dataSource-mssql" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
        <property name="driverClassName" value="com.microsoft.sqlserver.jdbc.SQLServerDriver"/>
        <property name="url" value="jdbc:sqlserver:// server์ •๋ณด :1433;DataBaseName=๋””๋น„๋ช…"/>
        <property name="username" value="sa"/>
        <property name="password" value="๋น„๋ฐ€๋ฒˆํ˜ธ"/>
    </bean>
    

 

 

 

 

2.  context-mapper.xml ์„ค์ •ํ•˜๊ธฐ

 

์—ฌ๊ธฐ์„œ ์ค‘์š”ํ•œ๊ฒŒ 

<!-- SqlSession setup for MyBatis Database Layer -->
<bean id="sqlSession" class="egovframework.ccms.cmmn.RefreshableSqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource-${Globals.DbType}" />
    <property name="configLocation" value="classpath:/egovframework/sqlmap/ccms/sql-mapper-config.xml" />
    <property name="mapperLocations" value="classpath:/egovframework/sqlmap/ccms/mappers/*.xml" />
    <property name="interval" value="1000" />
    <property name="databaseIdProvider" ref="databaseIdProvidor"></property>
</bean>

<!-- MapperConfigurer setup for MyBatis Database Layer with @Mapper("deptMapper") in DeptMapper Interface -->
<bean class="egovframework.rte.psl.dataaccess.mapper.MapperConfigurer">
    <property name="basePackage" value="egovframework.ccms.*.mapper" />
    <property name="sqlSessionFactoryBeanName" value="sqlSession" />
</bean>

 

 

package๋ช…์—์„œ mapper ํด๋”๋ช…์ด ๊ฒน์น˜๋ฉด ์•ˆ๋˜๋Š”๋ฐ 

 

๋‚˜๋Š” ํด๋”๋ช…์„ mapper๋กœ ๋™์ผํ•˜๊ฒŒ ์ฃผ๊ณ   

.xml ํŒŒ์ผ๋ช… ์ด๋ฆ„๋งŒ ๋‹ค๋ฅด๊ฒŒ ์คŒ;;;

 

๊ทธ๋ž˜๋†“๊ณ  ์—ฐ๊ฒฐ๋˜๊ธธ ๋ฐ”๋žฌ๋‹ค. . ๋Œ€ ์™• ์‹ค ์ˆ˜ 

 

<!-- MSSQL -->
<!-- SqlSession setup for MyBatis Database Layer -->
<bean id="sqlSessionMssql" class="egovframework.ccms.cmmn.RefreshableSqlSessionFactoryBean">
    <property name="dataSource" ref="dataSource-mssql"/>
    <property name="configLocation" value="classpath:/egovframework/sqlmap/ccms/sql-mapper-config.xml" />
    <property name="mapperLocations" value="classpath:/egovframework/sqlmap/ccms/mssql/mappers/*.xml" />
    <property name="interval" value="1000" />
	<property name="databaseIdProvider" ref="databaseIdProvidor"></property>
</bean>

<!-- MapperConfigurer setup for MyBatis Database Layer with @Mapper("deptMapper") in DeptMapper Interface -->
<bean class="egovframework.rte.psl.dataaccess.mapper.MapperConfigurer">
	<property name="basePackage" value="egovframework.ccms.*.mapper2" />
	<property name="sqlSessionFactoryBeanName" value="sqlSessionMssql" />
</bean>

 

3. package ๋งŒ๋“ค์–ด์„œ ํ…Œ์ŠคํŠธ 

 

tibero DB  / ์›๋ž˜ ํด๋” mapper 

 

 

mssql DB

 

 

context-mapper.xml ์„ค์ •๋Œ€๋กœ

ํด๋”๋ช… mapper2๋กœ ๋ณ€๊ฒฝ 

 

๊ทธ๋ฆฌ๊ณ  

jspํ™”๋ฉด

 ๋งŒ๋“ค์–ด ํ…Œ์ŠคํŠธํ•˜๋ฉด ๋ !