我正在开发从 PCF (Pivotal Cloud FoundrY) 用户提供的服务获取 DS 的应用程序。它工作正常,但我想了解如何定义验证间隔。
由于 Spring 和 PCF 正在管理我的连接池。我想了解它是如何工作的。
public DataSource getProfileDS() {
PoolConfig poolConfig = new PoolConfig(5, 10, 30000);
DataSourceConfig dsConfig = new DataSourceConfig(poolConfig, null);
return connectionFactory().dataSource("profileDS", dsConfig);
}
还有,有没有办法像我们在tomcat下那样自己设置验证间隔?
最佳答案
How spring cloud defines validation interval under the Pivotal Cloud Foundry?
Spring Cloud Config 将定义适合您的关系数据库的验证查询。
示例:
至于验证间隔,看起来没有被配置。相反,DBCP-like pools使用testOnBorrow
,和Hikari配置为使用connectionTestQuery
。在从池中获取连接之前进行测试时,无需设置验证间隔。
Also, is there any way to set up the validation interval by my own like we are used to do under the tomcat?
如果您要使用 Spring Cloud 连接器,则不需要,但您不必使用 Spring Cloud 连接器。您还可以通过其他几种方法来实现此目的。
- Spring Boot 公开
VCAP_SERVICES
作为类似vcap.services.<name>.credentials.username
的属性。您可以使用它们来手动定义数据源。请参阅here . - 您可以使用新的 java-cfenv库,即 intended to complement Spring Boot better .
希望有帮助!
关于java - Spring Cloud在Pivotal Cloud Foundry下如何定义验证间隔?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56239718/