How to set custom connection properties on DataSource in Spring Boot 1.3.x with default Tomcat connection pool

后端 未结 4 1486
再見小時候
再見小時候 2020-12-31 11:01

I need to set some specific Oracle JDBC connection properties in order to speed up batch INSERTs (defaultBatchValue) and mass SELECTs

4条回答
  •  星月不相逢
    2020-12-31 11:14

    Some additional information to complement the answer by @Cyril. If you want to upvote use his answer, not mine.

    I was a little bit puzzled how easy it is to set additional connection properties that in the end get used while creating the database connection. So I did a little bit of research.

    spring.datasource.connectionProperties is not mentioned in the reference. I created an issue because of this. If I had used the Spring Boot YML editor, I would have seen which properties are supported. Here is what STS suggests when you create an application.yml and hit Ctrl+Space:

    The dash does not matter because of relaxed binding but if you interpret it literally the propertys name is spring.datasource.connection-properties.

    The correct setup in application.yml looks like this:

    spring:
        datasource:
            connection-properties: defaultBatchValue=1000;defaultRowPrefetch=1000
            ...
    

    This gets honored which is proven by my perf4j measurements of mass SELECTs.

    Before:

    2016-01-19 08:58:32.604 INFO 15108 --- [ main] org.perf4j.TimingLogger : start[1453190311227] time[1377] tag[get elements]

    After:

    2016-01-19 08:09:18.214 INFO 9152 --- [ main] org.perf4j.TimingLogger : start[1453187358066] time[147] tag[get elements]

    The time taken to complete the SQL statement drops from 1377ms to 147, which is an enormous gain in performance.

提交回复
热议问题