Commit f6816a26 by nobodyiam

use custom connection validator instead of sending SELECT 1 query

parent 425f0e94
package com.ctrip.framework.apollo.common.utils;
import org.apache.tomcat.jdbc.pool.Validator;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import java.sql.Connection;
/**
* @author Jason Song(song_s@ctrip.com)
*/
public class DataSourceValidator implements Validator {
private static final Logger LOGGER = LoggerFactory.getLogger(DataSourceValidator.class);
private static final int DEFAULT_VALIDATE_TIMEOUT_IN_SECONDS = 5;
@Override
public boolean validate(Connection connection, int validateAction) {
boolean isValid = false;
try {
isValid = connection.isValid(DEFAULT_VALIDATE_TIMEOUT_IN_SECONDS);
} catch (Throwable ex) {
LOGGER.warn("Data source validation error", ex);
}
return isValid;
}
}
......@@ -3,7 +3,8 @@ spring.http.converters.preferred-json-mapper=gson
# DataSource
spring.datasource.testWhileIdle=true
spring.datasource.testOnBorrow=true
spring.datasource.validationQuery=SELECT 1
spring.datasource.validatorClassName=com.ctrip.framework.apollo.common.utils.DataSourceValidator
spring.datasource.validationInterval=5000
spring.datasource.initSQL=set names utf8mb4
# Naming strategy
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment