您好, 欢迎来到 !    登录 | 注册 | | 设为首页 | 收藏本站

SpringBoot2 整合sharding-jdbc 启动报错,坑多多

bubuko 2022/1/25 19:43:15 java 字数 6319 阅读 1753 来源 http://www.bubuko.com/infolist-5-1.html

原文地址:https://www.520mwx.com/view/93143 1、查看项目是否引入自动配置的数据源(比如druid-spring-boot-starter),如果有,先删除,sharding启动时会自动创建数据源,两者冲突。如果还是想用druid链接池。引入: <dependency ...

 

原文地址:https://www.520mwx.com/view/93143

1、查看项目是否引入自动配置的数据源(比如druid-spring-boot-starter),如果有,先删除,sharding启动时会自动创建数据源,两者冲突。如果还是想用druid链接池。引入:

 

<dependency>
     <groupId>com.alibaba</groupId>
      <artifactId>druid</artifactId>
      <version>1.1.22</version>
 </dependency>

 

2、报错:

Caused by: java.sql.SQLFeatureNotSupportedException: getCatalog
	at org.apache.shardingsphere.shardingjdbc.jdbc.unsupported.AbstractUnsupportedOperationConnection.getCatalog(AbstractUnsupportedOperationConnection.java:91)
	at org.apache.shardingsphere.shardingjdbc.jdbc.core.datasource.EncryptDataSource.isTableExist(EncryptDataSource.java:88)

 

查看是否使用了flywaydb,如果有,删除掉,这个github上有人提了issues,可还是没有解决,参考这个,https://github.com/apache/shardingsphere/issues/2488

3、使用JPA-Hibernate的时候,报entityManager没注入,检查数据库驱动版本是否和数据库版本匹配

由于需要主从同步,分库就没做,这里贴一下分表的配置

id不要用数据库自增的方式

 

spring.shardingsphere.datasource.names=framework

spring.shardingsphere.datasource.framework.type=com.alibaba.druid.pool.DruidDataSource
spring.shardingsphere.datasource.framework.driver-class-name=com.mysql.jdbc.Driver
spring.shardingsphere.datasource.framework.url=
spring.shardingsphere.datasource.framework.username=
spring.shardingsphere.datasource.framework.password=

#article
spring.shardingsphere.sharding.tables.article.actual-data-nodes=framework.article$->{0..4}
spring.shardingsphere.sharding.tables.article.table-strategy.inline.sharding-column=id
spring.shardingsphere.sharding.tables.article.table-strategy.inline.algorithm-expression=article$->{id % 5}

spring.shardingsphere.sharding.tables.article_item.actual-data-nodes=framework.article$->{0..4}
spring.shardingsphere.sharding.tables.article_item.table-strategy.inline.sharding-column=id
spring.shardingsphere.sharding.tables.article_item.table-strategy.inline.algorithm-expression=article$->{id % 5}


#articles_attribute
spring.shardingsphere.sharding.tables.articles_attribute.actual-data-nodes=framework.articles_attribute$->{0..4}
spring.shardingsphere.sharding.tables.articles_attribute.table-strategy.inline.sharding-column=id
spring.shardingsphere.sharding.tables.articles_attribute.table-strategy.inline.algorithm-expression=articles_attribute$->{id % 5}

spring.shardingsphere.sharding.tables.articles_attribute_item.actual-data-nodes=framework.articles_attribute$->{0..4}
spring.shardingsphere.sharding.tables.articles_attribute_item.table-strategy.inline.sharding-column=id
spring.shardingsphere.sharding.tables.articles_attribute_item.table-strategy.inline.algorithm-expression=articles_attribute$->{id % 5}


spring.shardingsphere.props.sql.show=true






 

SpringBoot2 整合sharding-jdbc 启动报错,坑多多

原文:https://www.cnblogs.com/xibb/p/13083515.html


如果您也喜欢它,动动您的小指点个赞吧

除非注明,文章均由 laddyq.com 整理发布,欢迎转载。

转载请注明:
链接:http://laddyq.com
来源:laddyq.com
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。


联系我
置顶