天天看点

解决shardingsphere 4.1.1 SQLFeatureNotSupportedException: isValid sharding-jdbc

shardingsphere 4.1.1  SQLFeatureNotSupportedException: isValid 解决办法

替换如下两个JAR

sharding-jdbc-orchestration-4.1.1.jar

sharding-jdbc-core-4.1.1.jar

下载链接

https://download.csdn.net/download/nuliyang/14363740

参考下面链接,更改源码

https://github.com/apache/shardingsphere/pull/6002/files/c191c9571ab5a2e9e6d3f0c0f84c8bb6cd36d851

AbstractConnectionAdapter

@Override

    public final boolean isValid(final int timeout) throws SQLException {

        for (Connection connection : cachedConnections.values()) {

            if (!connection.isValid(timeout)) {

                return false; 

            }

        }

        return true;

    }

CircuitBreakerConnection

ShadowConnection

EncryptConnection

  @Override

public boolean isValid(final int timeout) {

    return true;

}

异常日志

org.springframework.dao.InvalidDataAccessApiUsageException: ConnectionCallback; isValid; nested exception is java.sql.SQLFeatureNotSupportedException: isValid

    at org.springframework.jdbc.support.SQLExceptionSubclassTranslator.doTranslate(SQLExceptionSubclassTranslator.java:96) ~[spring-jdbc-5.2.8.RELEASE.jar:5.2.8.RELEASE]

    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:72) ~[spring-jdbc-5.2.8.RELEASE.jar:5.2.8.RELEASE]

    at org.springframework.jdbc.support.AbstractFallbackSQLExceptionTranslator.translate(AbstractFallbackSQLExceptionTranslator.java:81) ~[spring-jdbc-5.2.8.RELEASE.jar:5.2.8.RELEASE]

    at org.springframework.jdbc.core.JdbcTemplate.translateException(JdbcTemplate.java:1443) ~[spring-jdbc-5.2.8.RELEASE.jar:5.2.8.RELEASE]

    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:336) ~[spring-jdbc-5.2.8.RELEASE.jar:5.2.8.RELEASE]

    at org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator.isConnectionValid(DataSourceHealthIndicator.java:130) ~[spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator.doDataSourceHealthCheck(DataSourceHealthIndicator.java:116) ~[spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator.doHealthCheck(DataSourceHealthIndicator.java:100) ~[spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.health.AbstractHealthIndicator.health(AbstractHealthIndicator.java:82) ~[spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.health.HealthIndicator.getHealth(HealthIndicator.java:37) [spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.health.HealthEndpoint.getHealth(HealthEndpoint.java:71) [spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.health.HealthEndpoint.getHealth(HealthEndpoint.java:39) [spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.health.HealthEndpointSupport.getContribution(HealthEndpointSupport.java:99) [spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.health.HealthEndpointSupport.getAggregateHealth(HealthEndpointSupport.java:110) [spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.health.HealthEndpointSupport.getContribution(HealthEndpointSupport.java:96) [spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.health.HealthEndpointSupport.getHealth(HealthEndpointSupport.java:74) [spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.health.HealthEndpointSupport.getHealth(HealthEndpointSupport.java:61) [spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.health.HealthEndpoint.health(HealthEndpoint.java:65) [spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.health.HealthEndpoint.health(HealthEndpoint.java:55) [spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]

    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]

    at org.springframework.util.ReflectionUtils.invokeMethod(ReflectionUtils.java:282) [spring-core-5.2.8.RELEASE.jar:5.2.8.RELEASE]

    at org.springframework.boot.actuate.endpoint.invoke.reflect.ReflectiveOperationInvoker.invoke(ReflectiveOperationInvoker.java:77) [spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.endpoint.annotation.AbstractDiscoveredOperation.invoke(AbstractDiscoveredOperation.java:60) [spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:121) [spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.boot.actuate.endpoint.jmx.EndpointMBean.invoke(EndpointMBean.java:96) [spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at com.sun.jmx.interceptor.DefaultMBeanServerInterceptor.invoke(DefaultMBeanServerInterceptor.java:819) [na:1.8.0_191]

    at com.sun.jmx.mbeanserver.JmxMBeanServer.invoke(JmxMBeanServer.java:801) [na:1.8.0_191]

    at javax.management.remote.rmi.RMIConnectionImpl.doOperation(RMIConnectionImpl.java:1468) [na:1.8.0_191]

    at javax.management.remote.rmi.RMIConnectionImpl.access$300(RMIConnectionImpl.java:76) [na:1.8.0_191]

    at javax.management.remote.rmi.RMIConnectionImpl$PrivilegedOperation.run(RMIConnectionImpl.java:1309) [na:1.8.0_191]

    at javax.management.remote.rmi.RMIConnectionImpl.doPrivilegedOperation(RMIConnectionImpl.java:1401) [na:1.8.0_191]

    at javax.management.remote.rmi.RMIConnectionImpl.invoke(RMIConnectionImpl.java:829) [na:1.8.0_191]

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]

    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]

    at sun.rmi.server.UnicastServerRef.dispatch(UnicastServerRef.java:357) [na:1.8.0_191]

    at sun.rmi.transport.Transport$1.run(Transport.java:200) [na:1.8.0_191]

    at sun.rmi.transport.Transport$1.run(Transport.java:197) [na:1.8.0_191]

    at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_191]

    at sun.rmi.transport.Transport.serviceCall(Transport.java:196) [na:1.8.0_191]

    at sun.rmi.transport.tcp.TCPTransport.handleMessages(TCPTransport.java:573) [na:1.8.0_191]

    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run0(TCPTransport.java:834) [na:1.8.0_191]

    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.lambda$run$0(TCPTransport.java:688) [na:1.8.0_191]

    at java.security.AccessController.doPrivileged(Native Method) [na:1.8.0_191]

    at sun.rmi.transport.tcp.TCPTransport$ConnectionHandler.run(TCPTransport.java:687) [na:1.8.0_191]

    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149) ~[na:1.8.0_191]

    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624) ~[na:1.8.0_191]

    at java.lang.Thread.run(Thread.java:748) ~[na:1.8.0_191]

Caused by: java.sql.SQLFeatureNotSupportedException: isValid

    at org.apache.shardingsphere.shardingjdbc.jdbc.unsupported.AbstractUnsupportedOperationConnection.isValid(AbstractUnsupportedOperationConnection.java:157) ~[sharding-jdbc-core-4.1.1.jar:4.1.1]

    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_191]

    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_191]

    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_191]

    at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_191]

    at org.springframework.jdbc.core.JdbcTemplate$CloseSuppressingInvocationHandler.invoke(JdbcTemplate.java:1525) ~[spring-jdbc-5.2.8.RELEASE.jar:5.2.8.RELEASE]

    at com.sun.proxy.$Proxy172.isValid(Unknown Source) ~[na:na]

    at org.springframework.boot.actuate.jdbc.DataSourceHealthIndicator.isConnectionValid(DataSourceHealthIndicator.java:134) ~[spring-boot-actuator-2.3.3.RELEASE.jar:2.3.3.RELEASE]

    at org.springframework.jdbc.core.JdbcTemplate.execute(JdbcTemplate.java:328) ~[spring-jdbc-5.2.8.RELEASE.jar:5.2.8.RELEASE]

    ... 47 common frames omitted