一.理解造成的原因

1.sharding没有实现isValid方法

参考类 AbstractUnsupportedOperationConnection

@Override
public final boolean isValid(final int timeout) throws SQLException {throw new SQLFeatureNotSupportedException("isValid");
}

2. 调用isValid的原因

参考类DataSourceHealthIndicator

创建DataSourceHealthIndicator时没有传递query进来导致query为空

private DataSource dataSource;private String query;private JdbcTemplate jdbcTemplate;
public DataSourceHealthIndicator() {this(null, null);
}/*** Create a new {@link DataSourceHealthIndicator} using the specified* {@link DataSource}.* @param dataSource the data source*/
public DataSourceHealthIndicator(DataSource dataSource) {this(dataSource, null);
}/*** Create a new {@link DataSourceHealthIndicator} using the specified* {@link DataSource} and validation query.* @param dataSource the data source* @param query the validation query to use (can be {@code null})*/
public DataSourceHealthIndicator(DataSource dataSource, String query) {super("DataSource health check failed");this.dataSource = dataSource;this.query = query;this.jdbcTemplate = (dataSource != null) ? new JdbcTemplate(dataSource) : null;
}

开始进行检查,发现query字段为null,开始调用jdbc自带的isValid()方法

@Override
protected void doHealthCheck(Health.Builder builder) throws Exception {if (this.dataSource == null) {builder.up().withDetail("database", "unknown");}else {doDataSourceHealthCheck(builder);}
}private void doDataSourceHealthCheck(Health.Builder builder) throws Exception {builder.up().withDetail("database", getProduct());String validationQuery = this.query;if (StringUtils.hasText(validationQuery)) {builder.withDetail("validationQuery", validationQuery);// Avoid calling getObject as it breaks MySQL on Java 7 and laterList<Object> results = this.jdbcTemplate.query(validationQuery, new SingleColumnRowMapper());Object result = DataAccessUtils.requiredSingleResult(results);builder.withDetail("result", result);}else {builder.withDetail("validationQuery", "isValid()");boolean valid = isConnectionValid();builder.status((valid) ? Status.UP : Status.DOWN);}
}
private Boolean isConnectionValid() {return this.jdbcTemplate.execute((ConnectionCallback<Boolean>) this::isConnectionValid);
}
private Boolean isConnectionValid(Connection connection) throws SQLException {return connection.isValid(0);
}

最后调用AbstractUnsupportedOperationConnection的isValid()方法导致抛出异常

二.解决方法

1.方法一 对shardingsphere进行增强

重新对类AbstractUnsupportedOperationConnection编写

对类org.apache.shardingsphere.driver.jdbc.adapter.AbstractConnectionAdapter进行修改

复写isValid()方法

@Override
    public final boolean isValid(final int timeout) throws SQLException {
        for (Connection connection : cachedConnections.values()) {
            if (!connection.isValid(timeout)) {
                return false;
            }
        }
        return true;
    }

对类org.apache.shardingsphere.shardingjdbc.jdbc.unsupported.AbstractUnsupportedOperationConnection进行修改

删除isValid()方法

//@Override
//public final boolean isValid(final int timeout) throws SQLException {
//    throw new SQLFeatureNotSupportedException("isValid");
//}

完成后替换2个jar包 sharding-jdbc-orchestration-*.jar 及 sharding-jdbc-core-*.jar

2.方法二暂时关闭actuator对db的监控

配置参数

//application.properties
management.health.db.enabled=false

解决使用sharding-jdbc-spring-boot-starter 造成SQLFeatureNotSupportedException: isValid的问题相关推荐

  1. 【MySQL 读写分离】Sharding JDBC + Spring boot 实现数据库读写分离的登录 Demo

    上篇文章我们搭建了 MySQL 数据库主从复制集群 MySQL 搭建主从复制集群~~~ 本篇文章我们利用搭建好的主从复制集群,使用 SpringBoot 结合 Sharding-JDBC 搭建一个小的 ...

  2. 自定义 Spring Boot Starter

    一.引言 什么是Spring Boot Starter呢?我们直接来看看官网是怎么介绍的吧. Starters are a set of convenient dependency descripto ...

  3. 一个项目有两个pom_实现一个Spring Boot Starter超简单,读 Starter 源码也不在话下...

    Spring Boot 对比 Spring MVC 最大的优点就是使用简单,约定大于配置.不会像之前用 Spring MVC 的时候,时不时被 xml 配置文件搞的晕头转向,冷不防还因为 xml 配置 ...

  4. 实现一个 Spring Boot Starter 原来如此简单,读 Starter 源码也不在话下

    我是风筝,公众号「古时的风筝」,一个在程序圈混迹多年,主业 Java,另外 Python.React 也玩儿的 6 的斜杠开发者.现已转行程序员鼓励师 Spring Cloud 系列文章已经完成,可以 ...

  5. 手把手教你定制标准 Spring Boot starter

    点击上方蓝色"程序猿DD",选择"设为星标" 回复"资源"获取独家整理的学习资料! 写在前面 我们每次构建一个 Spring 应用程序时,我 ...

  6. 一个简易上手的短信服务Spring Boot Starter,连傻瓜都会!

    作 者:jackieonway 来 源:jianshu.com/u/36510c75d37c 短信服务在用户注册.登录.找回密码等相关操作中,可以让用户使用更加便捷,越来越多的公司都采用短信验证的方式 ...

  7. 快速开发一个自定义 Spring Boot Starter ,希望你也会

    来源:http://t.cn/Ai9li9fC 众所周知,Spring Boot由众多Starter组成,随着版本的推移Starter家族成员也与日俱增.在传统Maven项目中通常将一些层.组件拆分为 ...

  8. 自定义依赖注解无效_最详细的自定义Spring Boot Starter开发教程

    1.前言 随着Spring的日渐臃肿,为了简化配置.开箱即用.快速集成,Spring Boot 横空出世.目前已经成为 Java 目前最火热的框架了.平常我们用Spring Boot开发web应用.S ...

  9. Spring boot starter

    1:Spring boot starter及项目中的类似运用 1:Spring boot starter的两种方式 引入pom文件,自动管理jar版本 根据spring.factories配置文件,加 ...

  10. 《SpringCloud超级入门》Spring Boot Starter的介绍及使用《七》

    目录 Spring Boot Starter项目创建 自动创建客户端 使用 Starter 使用注解开启 Starter 自动构建 使用配置开启 Starter 自动构建 配置 Starter 内容提 ...

最新文章

  1. STM32分类及命名方法
  2. 如何在SAP Spartacus里增添自定义的配置条目
  3. python readline_16.8. readline — GNU readline 接口 — Python 2.7.18 文档
  4. Scala 入门3(类、Trait、模式匹配、正则、异常、提取器、IO)
  5. angular js 默认选中_AngularJS Select(选择框)
  6. layui引入php项目,怎么将layui引入开发框架中
  7. 团队任务3 每日立会
  8. ubuntu14.10 linux-header更新,Ubuntu 14.04 怎样升级到 Ubuntu 14.10
  9. Android 开发未来的出路何在? | 技术头条
  10. java中获得IP地址
  11. IBM的人工智能“沃森”首次确诊罕见白血病,只用了10分钟!
  12. prerenderspaplugin可以抓取动态数据吗_RPA编程思路之数据抓取
  13. mysql客户端介绍
  14. 达内android 代码,【达内唯一总部】Android实现获取系统应用列表-达内Android分享...
  15. 计算机桌面常见故障,电脑常见故障问题以及解决办法
  16. Sql Server 2008服务启动失败,错误17058
  17. kindle paperwhite2 越狱备忘
  18. Visual Studio 快速统一设置项目属性(以VS2017为例)
  19. ubuntu系统更新后分辨率变低的问题之一
  20. vue 报错:WebSocket connection to ‘ws://192.168.51.116:3000/ws‘ failed:

热门文章

  1. GitHub上超火的“算法宝典”,程序员开发指南
  2. Qt网络编程01-QTcpSocket和QTcpServer的基本使用
  3. python 力扣(LeetCode) 1818.绝对差值和
  4. MD5加密算法原理及实现
  5. 2020-09-20
  6. spark学习之SparkStreaming
  7. 完美解决苹果电脑mac终端无法输入大写T的问题
  8. Windows 10 开启卓越性能模式
  9. 网页版查询mysql数据_网页查询数据库 数据库查询
  10. 计算机如何用vb文本加密,VB 实现中文文本的加密方法