且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Spring Boot数据源tomcat jdbc属性不起作用

更新时间:2022-10-20 17:02:22

尝试升级Spring引导版本, 1.5.10-RELEASE 是当前版本。 / p>

此外,我发现我的应用程序的连接池属性不是b当包含属性前缀 tomcat 时应用。如果仍然遇到问题,请尝试将其删除。





spring.datasource.tomcat.max-active = 200



成为



spring.datasource.max-active = 200



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


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.

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