커넥션 풀 : 매번 DataSource를 사용하여 연결하지 않고, 미리 연결을 맺어두고 반환하는 방식
1. pom.xml에 HikariCP추가
<dependency>
<groupId>com.zaxxer</groupId>
<artifactId>HikariCP</artifactId>
<version>2.7.4</version>
</dependency>
2. root-context.xml 설정
<?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:mybatis-spring="http://mybatis.org/schema/mybatis-spring"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://mybatis.org/schema/mybatis-spring http://mybatis.org/schema/mybatis-spring-1.2.xsd
http://www.springframework.org/schema/beans https://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.3.xsd">
<!-- Root Context: defines shared resources visible to all other web components -->
<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig">
<!-- <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property> -->
<property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"></property>
<!-- <property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1522:jun"></property> -->
<property name="jdbcUrl" value="jdbc:log4jdbc:oracle:thin:@localhost:1522:jun"></property>
<property name="username" value="아이디"></property>
<property name="password" value="패스워드"></property>
</bean>
<!-- HikariCP configuration -->
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close">
<constructor-arg ref="hikariConfig"/>
</bean>
<bean id="sqlSessionFactory" class="org.mybatis.spring.SqlSessionFactoryBean">
<property name="dataSource" ref="dataSource"></property>
</bean>
<context:component-scan base-package="com.jjundol.service"></context:component-scan>
<mybatis-spring:scan base-package="com.jjundol.mapper"/>
</beans>
- root-context.xml은 스프링이 로딩될 때 확인하는 설정 파일로, 이미 만들어져 있는 클래스들을 활용하여 스프링이 Bean으로 등록할 때 사용함 (hikariConfig, dataSource)
- 외부 jar를 활용하는 클래스들은 <bean>을 활용
'WEB > spring' 카테고리의 다른 글
Maven 프로젝트 생성 (0) | 2020.04.28 |
---|---|
AOP예시 (0) | 2020.03.21 |
AOP (0) | 2020.03.21 |
REST 예시 (0) | 2020.02.27 |
이클립스 프로젝트 JDBC 연결 (0) | 2019.12.30 |