spring boot datasource tomcat jdbc properties not working

情到浓时终转凉″ 提交于 2019-12-11 06:19:50

问题


I have a Spring Boot application (version 1.5.1.RELEASE) and I am using spring-boot-starter-data-jpa as a dependency to manage my database. I am using postgres as my database and configured it using the below properties.

spring.datasource.url=${POSTGRES_URL}
spring.datasource.username=${POSTGRES_USER}

Now when I run my tests which are almost 120, I get too many client already open error for abou 10 test cases while starting the test case itself and it fails.(remaining 100 test cases pass with success as they are able to get a connection to database)

First thing I did is increased my default postgres max connections count from 100 to 200 in the postgres server config file and my tests pass successfully after this change.

Now I investigated a bit and tried setting the parameters for connection pooling properties such as :

spring.datasource.tomcat.max-active=200
spring.datasource.tomcat.test-on-borrow=true
spring.datasource.tomcat.max-wait=10000

However these properties do not work and the tests fails again giving the same error as above. I tried reading from multiple different blogs and spring documentation for setting the connection pool properties but did not find what might be going wrong with me.

I also think that if I set the above property spring.datasource.tomcat.max-active to 100 connections it should work with the help of tomcat jdbc pooling as i think in current scenario it is trying to open a new connection to database for each test case and I am in a fear that this same scenario might happen when I deploy this code to production environment and a new connection will be opened to the database for each request.

Does anyone have faced this problem before or is there something wrong I am doing.

Thanks in advance for the help.


回答1:


Try upgrading Spring boot version, 1.5.10-RELEASE is the current version.

Also, I found the connection pool properties for my application were not being applied when the property prefix tomcat was included. If you are still having issues try removing that.

i.e.

spring.datasource.tomcat.max-active=200

Becomes

spring.datasource.max-active=200

See https://artofcode.wordpress.com/2017/10/19/spring-boot-configuration-for-tomcats-pooling-data-source



来源:https://stackoverflow.com/questions/43351733/spring-boot-datasource-tomcat-jdbc-properties-not-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!