Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to change the dataSource to Druid on Shardingsphere JDBC5.4.0? #28779

Closed
renjiancheng opened this issue Oct 17, 2023 · 10 comments
Closed

How to change the dataSource to Druid on Shardingsphere JDBC5.4.0? #28779

renjiancheng opened this issue Oct 17, 2023 · 10 comments

Comments

@renjiancheng
Copy link

Question

i try to use Shardingsphere JDBC 5.4.0 with Druid datasource in a springboot project, but it's not woking.

my application.yml

spring:
  datasource:
    driver-class-name: org.apache.shardingsphere.driver.ShardingSphereDriver
    url: jdbc:shardingsphere:classpath:shardingJdbc.yml
  autoconfigure:
    exclude: com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure

my shardingJdbc.yml

mode: # 不配置默认单机
  type: Standalone # 运行模式类型。可选配置:Standalone、Cluster
  repository:
    type: JDBC # 持久化仓库类型
dataSources:
  test:
    type: com.alibaba.druid.pool.DruidDataSource
    dataSourceClassName: com.alibaba.druid.pool.DruidDataSource
    driverClassName: com.mysql.jdbc.Driver
    url: jdbc:mysql://localhost:3306/test
    username: root
    password: zard
rules:
  - !SHARDING
    tables: # 数据分片规则配置
      customer:
        actualDataNodes: test.customer
        tableStrategy:
          standard:
            shardingColumn: customer_id
            shardingAlgorithmName: customer_id
        keyGenerateStrategy: # 分布式序列策略
          column: id
          keyGeneratorName: snowflake
    keyGenerators:
      snowflake:
        type: SNOWFLAKE
    shardingAlgorithms:
      customer_id:
        type: CLASS_BASED
        props:
          strategy: standard
          algorithmClassName: com.example.shardingjdbclearn.config.CspShardingAlgorithms
props:
  sql-show: true

my pom.xml

<?xml version="1.0" encoding="UTF-8"?>
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
         xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd">
    <modelVersion>4.0.0</modelVersion>
    <parent>
        <groupId>org.springframework.boot</groupId>
        <artifactId>spring-boot-starter-parent</artifactId>
        <version>2.6.15</version>
        <relativePath/> <!-- lookup parent from repository -->
    </parent>
    <groupId>com.example</groupId>
    <artifactId>sharding-jdbc-learn</artifactId>
    <version>0.0.1-SNAPSHOT</version>
    <name>sharding-jdbc-learn</name>
    <description>sharding-jdbc-learn</description>
    <properties>
        <java.version>1.8</java.version>
        <snakeyaml.version>1.33</snakeyaml.version>
        <shardingsphere.version>5.4.0</shardingsphere.version>
    </properties>
    <dependencies>
......
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>

        <dependency>
            <groupId>com.mysql</groupId>
            <artifactId>mysql-connector-j</artifactId>
            <scope>runtime</scope>
        </dependency>

        <dependency>
            <groupId>com.baomidou</groupId>
            <artifactId>mybatis-plus-boot-starter</artifactId>
            <version>3.5.3.2</version>
        </dependency>

        <dependency>
            <groupId>org.apache.shardingsphere</groupId>
            <artifactId>shardingsphere-jdbc-core</artifactId>
            <version>${shardingsphere.version}</version>
        </dependency>

        <dependency>
            <groupId>com.alibaba</groupId>
            <artifactId>druid-spring-boot-starter</artifactId>
            <version>1.2.16</version>
        </dependency>
    </dependencies>
 .....
</project>

the running log

Connected to the target VM, address: '127.0.0.1:56172', transport: 'socket'

  .   ____          _            __ _ _
 /\\ / ___'_ __ _ _(_)_ __  __ _ \ \ \ \
( ( )\___ | '_ | '_| | '_ \/ _` | \ \ \ \
 \\/  ___)| |_)| | | | | || (_| |  ) ) ) )
  '  |____| .__|_| |_|_| |_\__, | / / / /
 =========|_|==============|___/=/_/_/_/
 :: Spring Boot ::               (v2.6.15)

2023-10-16 17:59:24.532  INFO 93363 --- [           main] c.e.s.ShardingJdbcLearnApplication       : Starting ShardingJdbcLearnApplication using Java 1.8.0_381 on mbp.local with PID 93363 (/Users/renjiancheng/github/sharding-jdbc-learn/target/classes started by renjiancheng in /Users/renjiancheng/github/sharding-jdbc-learn)
2023-10-16 17:59:24.534  INFO 93363 --- [           main] c.e.s.ShardingJdbcLearnApplication       : No active profile set, falling back to 1 default profile: "default"
2023-10-16 17:59:25.103  INFO 93363 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat initialized with port(s): 8080 (http)
2023-10-16 17:59:25.107  INFO 93363 --- [           main] o.apache.catalina.core.StandardService   : Starting service [Tomcat]
2023-10-16 17:59:25.107  INFO 93363 --- [           main] org.apache.catalina.core.StandardEngine  : Starting Servlet engine: [Apache Tomcat/9.0.75]
2023-10-16 17:59:25.200  INFO 93363 --- [           main] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring embedded WebApplicationContext
2023-10-16 17:59:25.200  INFO 93363 --- [           main] w.s.c.ServletWebServerApplicationContext : Root WebApplicationContext: initialization completed in 525 ms
 _ _   |_  _ _|_. ___ _ |    _ 
| | |\/|_)(_| | |_\  |_)||_|_\ 
     /               |         
                        3.5.3.2 
2023-10-16 17:59:25.587  INFO 93363 --- [           main] o.s.b.w.embedded.tomcat.TomcatWebServer  : Tomcat started on port(s): 8080 (http) with context path ''
2023-10-16 17:59:25.592  INFO 93363 --- [           main] c.e.s.ShardingJdbcLearnApplication       : Started ShardingJdbcLearnApplication in 1.344 seconds (JVM running for 1.692)
2023-10-16 17:59:28.842  INFO 93363 --- [nio-8080-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/]       : Initializing Spring DispatcherServlet 'dispatcherServlet'
2023-10-16 17:59:28.842  INFO 93363 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Initializing Servlet 'dispatcherServlet'
2023-10-16 17:59:28.843  INFO 93363 --- [nio-8080-exec-1] o.s.web.servlet.DispatcherServlet        : Completed initialization in 1 ms
2023-10-16 17:59:28.893  INFO 93363 --- [nio-8080-exec-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Starting...
2023-10-16 17:59:29.041  INFO 93363 --- [nio-8080-exec-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Starting...
2023-10-16 17:59:29.115  INFO 93363 --- [nio-8080-exec-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-2 - Start completed.
2023-10-16 17:59:29.204  INFO 93363 --- [nio-8080-exec-1] com.alibaba.druid.pool.DruidDataSource   : {dataSource-1} inited
2023-10-16 17:59:30.960  INFO 93363 --- [nio-8080-exec-1] com.zaxxer.hikari.pool.PoolBase          : HikariPool-1 - Driver does not support get/set network timeout for connections. (getNetworkTimeout)
2023-10-16 17:59:30.961  INFO 93363 --- [nio-8080-exec-1] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Start completed.
2023-10-16 17:59:35.362 ERROR 93363 --- [nio-8080-exec-1] o.a.c.c.C.[.[.[/].[dispatcherServlet]    : Servlet.service() for servlet [dispatcherServlet] in context with path [] threw exception [Request processing failed; nested exception is org.springframework.jdbc.BadSqlGrammarException: 
### Error updating database.  Cause: java.sql.SQLException: Table 'user' doesn't exist
### The error may exist in com/example/shardingjdbclearn/mapper/UserMapper.java (best guess)
### The error may involve com.example.shardingjdbclearn.mapper.UserMapper.insert-Inline
### The error occurred while setting parameters
### SQL: INSERT INTO user  ( id, csp_id, name, age, create_time )  VALUES  ( ?, ?, ?, ?, ? )
### Cause: java.sql.SQLException: Table 'user' doesn't exist
; bad SQL grammar []; nested exception is java.sql.SQLException: Table 'user' doesn't exist] with root cause

java.sql.SQLException: Table 'user' doesn't exist
	at org.apache.shardingsphere.dialect.mysql.mapper.MySQLDialectExceptionMapper.toSQLException(MySQLDialectExceptionMapper.java:120) ~[shardingsphere-mysql-dialect-exception-5.4.0.jar:5.4.0]
	at org.apache.shardingsphere.dialect.mysql.mapper.MySQLDialectExceptionMapper.convert(MySQLDialectExceptionMapper.java:72) ~[shardingsphere-mysql-dialect-exception-5.4.0.jar:5.4.0]
	at org.apache.shardingsphere.dialect.SQLExceptionTransformEngine.toSQLException(SQLExceptionTransformEngine.java:59) ~[shardingsphere-dialect-exception-core-5.4.0.jar:5.4.0]
	at org.apache.shardingsphere.driver.jdbc.core.statement.ShardingSpherePreparedStatement.execute(ShardingSpherePreparedStatement.java:416) ~[shardingsphere-jdbc-core-5.4.0.jar:5.4.0]
	at com.zaxxer.hikari.pool.ProxyPreparedStatement.execute(ProxyPreparedStatement.java:44) ~[HikariCP-4.0.3.jar:na]
	at com.zaxxer.hikari.pool.HikariProxyPreparedStatement.execute(HikariProxyPreparedStatement.java) ~[HikariCP-4.0.3.jar:na]
	at org.apache.ibatis.executor.statement.PreparedStatementHandler.update(PreparedStatementHandler.java:48) ~[mybatis-3.5.13.jar:3.5.13]
	at org.apache.ibatis.executor.statement.RoutingStatementHandler.update(RoutingStatementHandler.java:75) ~[mybatis-3.5.13.jar:3.5.13]
	at org.apache.ibatis.executor.SimpleExecutor.doUpdate(SimpleExecutor.java:50) ~[mybatis-3.5.13.jar:3.5.13]
	at org.apache.ibatis.executor.BaseExecutor.update(BaseExecutor.java:117) ~[mybatis-3.5.13.jar:3.5.13]
	at org.apache.ibatis.executor.CachingExecutor.update(CachingExecutor.java:76) ~[mybatis-3.5.13.jar:3.5.13]
	at org.apache.ibatis.session.defaults.DefaultSqlSession.update(DefaultSqlSession.java:197) ~[mybatis-3.5.13.jar:3.5.13]
	at org.apache.ibatis.session.defaults.DefaultSqlSession.insert(DefaultSqlSession.java:184) ~[mybatis-3.5.13.jar:3.5.13]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_381]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_381]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_381]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_381]
	at org.mybatis.spring.SqlSessionTemplate$SqlSessionInterceptor.invoke(SqlSessionTemplate.java:425) ~[mybatis-spring-2.1.1.jar:2.1.1]
	at com.sun.proxy.$Proxy58.insert(Unknown Source) ~[na:na]
	at org.mybatis.spring.SqlSessionTemplate.insert(SqlSessionTemplate.java:272) ~[mybatis-spring-2.1.1.jar:2.1.1]
	at com.baomidou.mybatisplus.core.override.MybatisMapperMethod.execute(MybatisMapperMethod.java:59) ~[mybatis-plus-core-3.5.3.2.jar:3.5.3.2]
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy$PlainMethodInvoker.invoke(MybatisMapperProxy.java:148) ~[mybatis-plus-core-3.5.3.2.jar:3.5.3.2]
	at com.baomidou.mybatisplus.core.override.MybatisMapperProxy.invoke(MybatisMapperProxy.java:89) ~[mybatis-plus-core-3.5.3.2.jar:3.5.3.2]
	at com.sun.proxy.$Proxy59.insert(Unknown Source) ~[na:na]
	at com.example.shardingjdbclearn.web.TestController.register(TestController.java:33) ~[classes/:na]
	at com.example.shardingjdbclearn.web.TestController$$FastClassBySpringCGLIB$$d7258042.invoke(<generated>) ~[classes/:na]
	at org.springframework.cglib.proxy.MethodProxy.invoke(MethodProxy.java:218) ~[spring-core-5.3.27.jar:5.3.27]
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.invokeJoinpoint(CglibAopProxy.java:793) ~[spring-aop-5.3.27.jar:5.3.27]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:163) ~[spring-aop-5.3.27.jar:5.3.27]
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.27.jar:5.3.27]
	at org.springframework.transaction.interceptor.TransactionInterceptor$1.proceedWithInvocation(TransactionInterceptor.java:123) ~[spring-tx-5.3.27.jar:5.3.27]
	at org.springframework.transaction.interceptor.TransactionAspectSupport.invokeWithinTransaction(TransactionAspectSupport.java:388) ~[spring-tx-5.3.27.jar:5.3.27]
	at org.springframework.transaction.interceptor.TransactionInterceptor.invoke(TransactionInterceptor.java:119) ~[spring-tx-5.3.27.jar:5.3.27]
	at org.springframework.aop.framework.ReflectiveMethodInvocation.proceed(ReflectiveMethodInvocation.java:186) ~[spring-aop-5.3.27.jar:5.3.27]
	at org.springframework.aop.framework.CglibAopProxy$CglibMethodInvocation.proceed(CglibAopProxy.java:763) ~[spring-aop-5.3.27.jar:5.3.27]
	at org.springframework.aop.framework.CglibAopProxy$DynamicAdvisedInterceptor.intercept(CglibAopProxy.java:708) ~[spring-aop-5.3.27.jar:5.3.27]
	at com.example.shardingjdbclearn.web.TestController$$EnhancerBySpringCGLIB$$1129f82f.register(<generated>) ~[classes/:na]
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.8.0_381]
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62) ~[na:1.8.0_381]
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.8.0_381]
	at java.lang.reflect.Method.invoke(Method.java:498) ~[na:1.8.0_381]
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:205) ~[spring-web-5.3.27.jar:5.3.27]
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:150) ~[spring-web-5.3.27.jar:5.3.27]
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:117) ~[spring-webmvc-5.3.27.jar:5.3.27]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:895) ~[spring-webmvc-5.3.27.jar:5.3.27]
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:808) ~[spring-webmvc-5.3.27.jar:5.3.27]
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:87) ~[spring-webmvc-5.3.27.jar:5.3.27]
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:1072) ~[spring-webmvc-5.3.27.jar:5.3.27]
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:965) ~[spring-webmvc-5.3.27.jar:5.3.27]
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:1006) ~[spring-webmvc-5.3.27.jar:5.3.27]
	at org.springframework.web.servlet.FrameworkServlet.doPost(FrameworkServlet.java:909) ~[spring-webmvc-5.3.27.jar:5.3.27]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:555) ~[tomcat-embed-core-9.0.75.jar:4.0.FR]
	at org.springframework.web.servlet.FrameworkServlet.service(FrameworkServlet.java:883) ~[spring-webmvc-5.3.27.jar:5.3.27]
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:623) ~[tomcat-embed-core-9.0.75.jar:4.0.FR]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:209) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:51) ~[tomcat-embed-websocket-9.0.75.jar:9.0.75]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.springframework.web.filter.RequestContextFilter.doFilterInternal(RequestContextFilter.java:100) ~[spring-web-5.3.27.jar:5.3.27]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.27.jar:5.3.27]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.springframework.web.filter.FormContentFilter.doFilterInternal(FormContentFilter.java:93) ~[spring-web-5.3.27.jar:5.3.27]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.27.jar:5.3.27]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.springframework.web.filter.CharacterEncodingFilter.doFilterInternal(CharacterEncodingFilter.java:201) ~[spring-web-5.3.27.jar:5.3.27]
	at org.springframework.web.filter.OncePerRequestFilter.doFilter(OncePerRequestFilter.java:117) ~[spring-web-5.3.27.jar:5.3.27]
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:178) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:153) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:167) ~[tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:90) [tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:481) [tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:130) [tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:93) [tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:74) [tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:343) [tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:390) [tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:63) [tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:926) [tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1791) [tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:52) [tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1191) [tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.tomcat.util.threads.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:659) [tomcat-embed-core-9.0.75.jar:9.0.75]
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61) [tomcat-embed-core-9.0.75.jar:9.0.75]
	at java.lang.Thread.run(Thread.java:750) [na:1.8.0_381]

Disconnected from the target VM, address: '127.0.0.1:56172', transport: 'socket'
2023-10-16 18:01:22.423  INFO 93363 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown initiated...
2023-10-16 18:01:22.425  INFO 93363 --- [ionShutdownHook] com.zaxxer.hikari.HikariDataSource       : HikariPool-1 - Shutdown completed.

i only config a singe datasource of druid , but every time i try to use a database connection the druid and hikari are both inited,
image

why hikari datasource inited? how to disable it? and the table user is truly exsit, but why sql execute error and print 'Cause: java.sql.SQLException: Table 'user' doesn't exist'?

the project is here

thank you!

@renjiancheng
Copy link
Author

i also try to find answer at official document 、blog 、github issuses , i found nothing about this.

@zhanglinsong
Copy link

zhanglinsong commented Oct 18, 2023

i also try to find answer at official document 、blog 、github issuses , i found nothing about this.

user表没有配置规则, 说明是单表,不需要分库,加入以下配置

rules:
- !SINGLE
  tables:
    - test.user # 加载指定库指定单表

https://shardingsphere.apache.org/document/current/cn/user-manual/shardingsphere-jdbc/yaml-config/rules/single/
不清楚为什么会同时初始化hikari和druid,解决了说下

@renjiancheng
Copy link
Author

谢谢,按照你提醒的配置了单表以后确实程序能正常运行了,但是我之前看官方文档说是如果表不需要分库分表不需要单独配置呀?现在是变了吗?
image

如果只有部分数据库分库分表,是否需要将不分库分表的表也配置在分片规则中?
数据源同时加载的问题,我也还没头绪,解决了第一时间通知你。

@zhanglinsong
Copy link

谢谢,按照你提醒的配置了单表以后确实程序能正常运行了,但是我之前看官方文档说是如果表不需要分库分表不需要单独配置呀?现在是变了吗? image

如果只有部分数据库分库分表,是否需要将不分库分表的表也配置在分片规则中? 数据源同时加载的问题,我也还没头绪,解决了第一时间通知你。

5.4应该是更新了

@linghengqian
Copy link
Member

linghengqian commented Oct 19, 2023

<dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.2.16</version>
</dependency>
  • To be honest, after looking at your example in renjiancheng/sharding-jdbc-learn@ce5ae40 , I don't understand why you need to use com.alibaba:druid-spring-boot-starter instead of com.alibaba:druid. You don't configure Druid-specific Spring Boot Starter content in application.yml or a Spring Bean. You even actively excluded the configuration in com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure.

谢谢,按照你提醒的配置了单表以后确实程序能正常运行了,但是我之前看官方文档说是如果表不需要分库分表不需要单独配置呀?现在是变了吗?

and the table user is truly exsit, but why sql execute error and print 'Cause: java.sql.SQLException: Table 'user' doesn't exist'?

i only config a singe datasource of druid , but every time i try to use a database connection the druid and hikari are both inited, why hikari datasource inited?

  • This is completely reasonable. In fact, inside the initialized HikariCP DataSource you see is the ShardingSphere Standalone Mode initialized H2Database DataSource, which holds ShardingSphere metadata. If you switch to ShardingSphere Cluster Mode that uses any third-party metadata center, you will find that the same structure of data is stored in Zookeeper, Etcd, or another third-party metadata center. ShardingSphere implements reading and dynamic refresh of ShardingSphere's configuration through an SPI from a separate metadata center. This is reflected in the use of ContextManager within ShardingSphere JDBC and is further wrapped in DistSQL in ShardingSphere Proxy.

  • In general, HikariCP's DataSources were created because Standalone Mode required it, and ShardingSphere relies on HikariCP. If you don't want to see HikariCP data sources created, you'll need to implement SPI for Standalone Mode.

@renjiancheng
Copy link
Author

<dependency>
        <groupId>com.alibaba</groupId>
        <artifactId>druid-spring-boot-starter</artifactId>
        <version>1.2.16</version>
</dependency>
  • To be honest, after looking at your example in renjiancheng/sharding-jdbc-learn@ce5ae40 , I don't understand why you need to use com.alibaba:druid-spring-boot-starter instead of com.alibaba:druid. You don't configure Druid-specific Spring Boot Starter content in application.yml or a Spring Bean. You even actively excluded the configuration in com.alibaba.druid.spring.boot.autoconfigure.DruidDataSourceAutoConfigure.

谢谢,按照你提醒的配置了单表以后确实程序能正常运行了,但是我之前看官方文档说是如果表不需要分库分表不需要单独配置呀?现在是变了吗?

and the table user is truly exsit, but why sql execute error and print 'Cause: java.sql.SQLException: Table 'user' doesn't exist'?

i only config a singe datasource of druid , but every time i try to use a database connection the druid and hikari are both inited, why hikari datasource inited?

  • This is completely reasonable. In fact, inside the initialized HikariCP DataSource you see is the ShardingSphere Standalone Mode initialized H2Database DataSource, which holds ShardingSphere metadata. If you switch to ShardingSphere Cluster Mode that uses any third-party metadata center, you will find that the same structure of data is stored in Zookeeper, Etcd, or another third-party metadata center. ShardingSphere implements reading and dynamic refresh of ShardingSphere's configuration through an SPI from a separate metadata center. This is reflected in the use of ContextManager within ShardingSphere JDBC and is further wrapped in DistSQL in ShardingSphere Proxy.
  • In general, HikariCP's DataSources were created because Standalone Mode required it, and ShardingSphere relies on HikariCP. If you don't want to see HikariCP data sources created, you'll need to implement SPI for Standalone Mode.
    @zhanglinsong 加载hikari数据源是因为使用了standalone模式,默认使用它来连接h2维护shardingsphere元数据的,初始化逻辑在org.apache.shardingsphere.mode.repository.standalone.jdbc.JDBCRepository类里。
    @linghengqian thank you! it's very helpful, wish you good luck!

@linghengqian
Copy link
Member

  • @zzyReal666 I suggest you open a new issue and provide unit tests - because using Alibaba Druid does involve a bug in ShardingSphere 5.4.1 and is fixed by an unknown commit on the master branch.

@xwh4022
Copy link

xwh4022 commented Mar 13, 2024

  • @zzyReal666 I suggest you open a new issue and provide unit tests - because using Alibaba Druid does involve a bug in ShardingSphere 5.4.1 and is fixed by an unknown commit on the master branch.

Hello, may I know what bug it is? I also plan to use ShardingSphere 5.4.1 with Alibaba Druid...

@linghengqian
Copy link
Member

  • @zzyReal666 I suggest you open a new issue and provide unit tests - because using Alibaba Druid does involve a bug in ShardingSphere 5.4.1 and is fixed by an unknown commit on the master branch.

Hello, may I know what bug it is? I also plan to use ShardingSphere 5.4.1 with Alibaba Druid...

@xwh4022
Copy link

xwh4022 commented Mar 13, 2024

  • @zzyReal666 I suggest you open a new issue and provide unit tests - because using Alibaba Druid does involve a bug in ShardingSphere 5.4.1 and is fixed by an unknown commit on the master branch.

Hello, may I know what bug it is? I also plan to use ShardingSphere 5.4.1 with Alibaba Druid...

Get it, Thank you. I will review the issues submitted in the recent period.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

4 participants