ShardingJdbc SQLFeatureNotSupportedException: isValid
springboot集成 shardingjdbc 启动报错SQLFeatureNotSupportedException: isValid研究半天,看了shardingjdbc官网GitHub,也发现了这个问题:https://github.com/apache/shardingsphere/pull/6002/files/c191c9571ab5a2e9e6d3f0c0f84c8bb6cd36
springboot集成 shardingjdbc 启动报错
SQLFeatureNotSupportedException: isValid
研究半天,看了shardingjdbc官网GitHub,也发现了这个问题:
https://github.com/apache/shardingsphere/pull/6002/files/c191c9571ab5a2e9e6d3f0c0f84c8bb6cd36d851
然后特别记录一下: 解决方案:
package com.spark.fqdemoshardingsphere.config;
import org.springframework.beans.factory.ObjectProvider;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.actuate.autoconfigure.jdbc.DataSourceHealthContributorAutoConfiguration;
import org.springframework.boot.actuate.health.AbstractHealthIndicator;
import org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator;
import org.springframework.boot.jdbc.metadata.DataSourcePoolMetadataProvider;
import org.springframework.context.annotation.Configuration;
import org.springframework.util.StringUtils;
import javax.sql.DataSource;
import java.util.Map;
/**
* @author fuqiang
* @Description 数据源健康检查
* @Date 2021/7/9
*/
@Configuration
public class DataSourceHealthConfig extends DataSourceHealthContributorAutoConfiguration {
@Value("${spring.datasource.dbcp2.validation-query:select 1}")
private String defaultQuery;
public DataSourceHealthConfig(Map<String, DataSource> dataSources, ObjectProvider<DataSourcePoolMetadataProvider> metadataProviders) {
super(dataSources, metadataProviders);
}
@Override
protected AbstractHealthIndicator createIndicator(DataSource source) {
DataSourceHealthIndicator indicator = (DataSourceHealthIndicator) super.createIndicator(source);
if (!StringUtils.hasText(indicator.getQuery())) {
indicator.setQuery(defaultQuery);
}
return indicator;
}
}
参考文章:
https://blog.csdn.net/taopenglove/article/details/115008531?utm_medium=distribute.pc_relevant_download.none-task-blog-2defaultBlogCommendFromBaidudefault-10.test_version_3&depth_1-utm_source=distribute.pc_relevant_download.none-task-blog-2defaultBlogCommendFromBaidudefault-10.test_version_
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
所有评论(0)