Spring Boot数据源tomcat jdbc属性不起作用 [英] spring boot datasource tomcat jdbc properties not working

查看:392
本文介绍了Spring Boot数据源tomcat jdbc属性不起作用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Spring Boot应用程序(版本1.5.1.RELEASE),并且我使用 spring-boot-starter-data-jpa 作为管理我的数据库的依赖项。我将postgres用作数据库,并使用以下属性对其进行了配置。

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

现在运行测试时几乎有120个,在启动测试用例本身时,我收到太多关于10个测试用例的客户端已经打开的错误,但它失败了。(其余100个测试用例成功通过,因为它们能够连接到数据库)



我要做的第一件事是将postgres服务器配置文件中的默认postgres最大连接数从100增加到200,并且在此更改之后我的测试成功通过。



现在,我研究了一下,并尝试设置连接池属性的参数,例如:

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

但是这些属性不起作用,并且测试再次失败,并给出与上述相同的错误。我尝试从多个不同的博客和spring文档中阅读有关设置连接池属性的信息,但没有发现我可能出了什么问题。



我还认为,如果设置了上面的属性 spring.datasource.tomcat.max-active 到100个连接它应该在tomcat jdbc池的帮助下工作,因为我认为在当前情况下它正在尝试打开一个每个测试用例都与数据库建立了新的连接,当我将这段代码部署到生产环境中时,我担心会发生同样的情况,并且对于每个请求都会为数据库打开一个新的连接。



有人以前遇到过这个问题吗,或者我做错了什么事。



在此先感谢您的帮助。

解决方案

尝试升级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

这篇关于Spring Boot数据源tomcat jdbc属性不起作用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆