Spring-Boot: How do I set JDBC pool properties like maximum number of connections?

后端 未结 5 827
北荒
北荒 2020-11-28 02:26

Spring-Boot is a pretty awesome tool, but the documentation is a bit sparse when it comes to more advanced configuration. How can I set properties like the maximum size for

5条回答
  •  心在旅途
    2020-11-28 02:49

    Different connections pools have different configs.

    For example Tomcat (default) expects:

    spring.datasource.ourdb.url=...
    

    and HikariCP will be happy with:

    spring.datasource.ourdb.jdbc-url=...
    

    We can satisfy both without boilerplate configuration:

    spring.datasource.ourdb.jdbc-url=${spring.datasource.ourdb.url}
    

    There is no property to define connection pool provider.

    Take a look at source DataSourceBuilder.java

    If Tomcat, HikariCP or Commons DBCP are on the classpath one of them will be selected (in that order with Tomcat first).

    ... so, we can easily replace connection pool provider using this maven configuration (pom.xml):

        
            org.springframework.boot
            spring-boot-starter-jdbc
            
                
                    org.apache.tomcat
                    tomcat-jdbc
                
            
               
    
        
            com.zaxxer
            HikariCP
        
    

提交回复
热议问题