Notice
Recent Posts
Recent Comments
Link
«   2025/05   »
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
Tags
more
Archives
Today
Total
관리 메뉴

CODE NAME

[Spring] HikariCP 커넥션 풀 Java 8 버전 설정 본문

Spring

[Spring] HikariCP 커넥션 풀 Java 8 버전 설정

센우 2022. 4. 11. 12:19

라이브러리 추가

< pom.xml > 코드 추가

<!-- HikariCP -->
<dependency>
   <groupId>com.zaxxer</groupId>
   <artifactId>HikariCP</artifactId>
   <version>4.0.3</version>
</dependency>

 

 

DataSource 설정

< root-context.xml > 코드 추가

<bean id="hikariConfig" class="com.zaxxer.hikari.HikariConfig"> 
    <property name="driverClassName" value="oracle.jdbc.driver.OracleDriver"></property> 
    <property name="jdbcUrl" value="jdbc:oracle:thin:@localhost:1521:orcl"></property> 
    <property name="username" value="book_ex"></property> 
    <property name="password" value="book_ex"></property> 
</bean> 
 
<bean id="dataSource" class="com.zaxxer.hikari.HikariDataSource" destroy-method="close"> 
    <constructor-arg ref="hikariConfig"></constructor-arg> 
</bean>

 

테스트 코드

package com.peisia.persistence;

import java.sql.Connection;

import javax.sql.DataSource;

import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.test.context.ContextConfiguration;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;

@RunWith(SpringJUnit4ClassRunner.class)
@ContextConfiguration("file:src/main/webapp/WEB-INF/spring/root-context.xml")
public class DataSourceTests {
 
    @Autowired
    private DataSource dataSource;
    
    @Test
    public void testConnection() {
      
        try(Connection con = dataSource.getConnection();){
            
            System.out.println("con = " + con);
            
        } catch(Exception e) {
            
            e.printStackTrace();
            
        }
        
    }
    
}

 

Log4jdbc-log4j2 사용 시

DataSource 설정

< root-context.xml > 코드 변경

<property name="driverClassName" value="net.sf.log4jdbc.sql.jdbcapi.DriverSpy"></property>
<property name="jdbcUrl" value="jdbc:log4jdbc:oracle:thin:@localhost:1521:orcl"></property>

'Spring' 카테고리의 다른 글

No mapping found for HTTP request with URI [/favicon.ico]  (0) 2022.05.04
[Spring] 게시판 글 등록 시 한글 깨짐  (0) 2022.04.12
[Spring] @Log4j 오류  (0) 2022.04.11