[Spring-Framework] 40. Connection Pool - xml 정리(Oracle, MySQL, HikariCP, Apache DBCP)
root-context.xml과 같은 context.xml 파일에 빈스(Beans)로 등록해서 사용할 때 매우 요긴하게 사용될 수 있는 DataSource에 대해서 정리하였다.
의외로 정리된 자료를 찾기가 귀찮아서 정리하였으니 참고하여 잘 사용하면 된다.
연관 글은 38, 39번 Spring-Framework에도 적용해볼 수 있다.
1. 정리
많이 필요한 경우가 생긴다. 이거 찾는데 시간 허비하지 말라고 작성한다.
[추가]
<!-- MySQL - DataSource 셋팅 -->
<bean id="dataSource2" class="com.mysql.cj.jdbc.MysqlDataSource">
<property name="URL" value="${ORACLE_DB_URL}" />
<property name="user" value="${ORACLE_DB_USERNAME}"/>
<property name="password" value="${ORACLE_DB_PASSWORD}"/>
</bean>
<!-- <bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource"> -->
<!-- 2. Oracle - DataSource 셋팅 -->
<bean id="dataSource" class="oracle.jdbc.pool.OracleDataSource" destroy-method="close">
<property name="URL" value="${ORACLE_DB_URL}" />
<property name="user" value="${ORACLE_DB_USERNAME}"/>
<property name="password" value="${ORACLE_DB_PASSWORD}"/>
<property name="connectionCachingEnabled" value="true"/>
</bean>
<!-- 3. Apache DBCP -->
<bean id="dataSource" class="org.apache.commons.dbcp.BasicDataSource" destroy-method="close">
<property name="driverClassName" value="${jdbc.driverClassName}" />
<property name="url" value="${jdbc.url}" />
<property name="username" value="${jdbc.username}" />
<property name="password" value="${jdbc.password}" />
</bean>
<!-- 4. HikariCP -->
<!--
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<property name="driverClassName" value="oracle.jdbc.driver.OracleDriver" />
<property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:xe" />
<property name="username" value="username" />
<property name="password" value="password" />
</bean>
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg ref="hikariConfig"/>
</bean>
-->
<!-- 5. MariaDB -->
<!--
<bean id="dataSource4" class="org.springframework.jdbc.datasource.SimpleDriverDataSource">
<property name="driverClass" value="org.mariadb.jdbc.Driver"/>
<property name="url" value="jdbc:mariadb://localhost:3306/test"></property>
<property name="username" value="root"/>
<property name="password" value="test"/>
</bean>
-->
<!-- 6. MyBatis // 트랜젝션 적용 버전 -->
<!--
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource4"/>
<property name="configLocation" value="classpath:mybatis/config.xml"/>
<property name="mapperLocations" value="classpath:mybatis/sql/*.xml"></property>
</bean>
<bean id="sqlSession" class="org.mybatis.spring.SqlSessionTemplate">
<constructor-arg name="sqlSessionFactory" ref="sqlSessionFactory"/>
</bean>
<bean id="transactionManager" class="org.springframework.jdbc.datasource.DataSourceTransactionManager">
<property name="dataSource" ref="dataSource4"/>
</bean>
<tx:annotation-driven transaction-manager="transactionManager" proxy-target-class="true"/>
-->
2. 공식 사이트
http://commons.apache.org/proper/commons-dbcp/
https://github.com/brettwooldridge/HikariCP
-> 메뉴얼이 다소 부족하다. 깔끔하게 잘 정리는 되어 있는데 그런 점이 없는 건 아니다.