问题
I'm working on application that get the DS from PCF (Pivotal Cloud FoundrY) User provided services. It's working properly but I want to understand how the validation interval is defined.
As Spring and PCF are managing my connection pool. I'd like to understand how that works.
public DataSource getProfileDS() {
PoolConfig poolConfig = new PoolConfig(5, 10, 30000);
DataSourceConfig dsConfig = new DataSourceConfig(poolConfig, null);
return connectionFactory().dataSource("profileDS", dsConfig);
}
Also, is there any way to set up the validation interval by my own like we are used to do under the tomcat?
回答1:
How spring cloud defines validation interval under the Pivotal Cloud Foundry?
Spring Cloud Config will define a validation query that is appropriate for your relational database.
Examples:
- MySQL
- Oracle
- Postgres
As to the validation interval, it does not look like that's being configured. Instead, the DBCP-like pools use testOnBorrow
, and Hikari is configured to use connectionTestQuery
. When testing before obtaining a connection from the pool, setting the validation interval is unnecessary.
Also, is there any way to set up the validation interval by my own like we are used to do under the tomcat?
Not if you're going to use Spring Cloud Connectors, but you don't have to use Spring Cloud Connectors. There's a couple of other ways you can do this.
- Spring Boot exposes
VCAP_SERVICES
as properties likevcap.services.<name>.credentials.username
. You could use those to manually define a DataSource. See here. - You can use the new java-cfenv library, which is intended to complement Spring Boot better.
Hope that helps!
来源:https://stackoverflow.com/questions/56239718/how-spring-cloud-defines-validation-interval-under-the-pivotal-cloud-foundry