반응형

스프링 부트의 기본 커넥션 풀이 원래 Tomcat JDBC Connection Pool 이었는데 2.0.0 버전 부터 HikariCP 로 변경 되었습니다.


1.5.9 RELEASE

29.1.2 Connection to a production database

Production database connections can also be auto-configured using a pooling DataSource. Here’s the algorithm for choosing a specific implementation:

  • We prefer the Tomcat pooling DataSource for its performance and concurrency, so if that is available we always choose it.
  • Otherwise, if HikariCP is available we will use it.
  • If neither the Tomcat pooling datasource nor HikariCP are available and if Commons DBCP is available we will use it, but we don’t recommend it in production and its support is deprecated.
  • Lastly, if Commons DBCP2 is available we will use it.

If you use the spring-boot-starter-jdbc or spring-boot-starter-data-jpa ‘starters’ you will automatically get a dependency to tomcat-jdbc.



2.0.0 RELEASE

29.1.2 Connection to a Production Database

Production database connections can also be auto-configured by using a pooling DataSource. Spring Boot uses the following algorithm for choosing a specific implementation:

  1. We prefer HikariCP for its performance and concurrency. If HikariCP is available, we always choose it.
  2. Otherwise, if the Tomcat pooling DataSource is available, we use it.
  3. If neither HikariCP nor the Tomcat pooling datasource are available and if Commons DBCP2 is available, we use it.

If you use the spring-boot-starter-jdbc or spring-boot-starter-data-jpa “starters”, you automatically get a dependency to HikariCP.


그래서 2.0 버전 부터는 Tomcat JDBC Connection Pool 을 쓰려면 몇 가지 설정 추가해야 합니다.


application.properties 에서 어떤 데이터소스를 사용할지 명시해야 합니다.

1
spring.datasource.type=org.apache.tomcat.jdbc.pool.DataSource


그리고 tomcat-jdbc 라이브러리도 가 추가 되어야합니다. 

<maven - pom.xml>

1
2
3
4
5
6
    <!-- tomcat-jdbc -->
    <dependency>
      <groupId>org.apache.tomcat</groupId>
      <artifactId>tomcat-jdbc</artifactId>
      <scope>provided</scope>
    </dependency>



application.properties 에 tomcat connection pool 설정입니다. 위의 2가지를 설정하지 않으면 아래 설정이 동작하지 않습니다.

1
2
3
4
5
6
7
8
9
spring.datasource.tomcat.max-active=50
spring.datasource.tomcat.max-idle=50
spring.datasource.tomcat.min-idle=10
spring.datasource.tomcat.max-wait=-1
spring.datasource.tomcat.initial-size=10
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.test-while-idle=true
spring.datasource.tomcat.validation-query=select 'GONI'
spring.datasource.tomcat.time-between-eviction-runs-millis=3000


반응형

+ Recent posts