使用ShardingSphere 过程中遇到的关于spring boot 版本的问题

时间:2022-07-26
本文章向大家介绍使用ShardingSphere 过程中遇到的关于spring boot 版本的问题,主要内容包括其使用实例、应用技巧、基本知识点总结和需要注意事项,具有一定的参考价值,需要的朋友可以参考一下。

直接上关键词吧 不是什么技术文章,采坑记录一下 写完还得去自己做实验 手动狗头

org.springframework.beans.factory.BeanCreationException: Error creating bean with name

  'org.apache.shardingsphere.shardingjdbc.spring.boot.SpringBootConfiguration': 
  Initialization of bean failed; nested exception is org.apache.shardingsphere.core.exception.ShardingException: 
  Can't find datasource type!

org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'org.apache.shardingsphere.shardingjdbc.spring.boot.SpringBootConfiguration': Initialization of bean failed; nested exception is org.apache.shardingsphere.core.exception.ShardingException: Can't find datasource type!

Can't find datasource type!

这个数据源类型: 还记得springboot 会默认一个数据源的链接类型,

报错向下看:

Caused by: java.lang.ClassNotFoundException: com.zaxxer.hikari.HikariDataSource

com.zaxxer.hikari.HikariDataSource 这个应该眼熟点吧

ShardingSphere 的官方git上的demo 使用的spring boot 版本是 1.5.17 然后我也使用的这个版本,配置好配置文件后,但启动springboot后 报了上面这个错误。

奇怪当我启动官方的demo 时是没有出错的啊,后来看到下面的这个错

Caused by: java.lang.ClassNotFoundException: com.zaxxer.hikari.HikariDataSource 又看了官方的demo ,是自己在pom中引入的 HikariDataSource 的,我自己也引入后,启动成功。

spirng boot 2 x 是要默认把 com.zaxxer.hikari.HikariDataSource 作为数据源的。

spring boot 1.5的 application.properties 的设置中 是可以由“_” 下划线的,但sprng boot 不知道哪个版本后就会不能使用 必须用“-”

中横向替换

翻译都能看懂些应该:

Description:

Configuration property name 'spring.shardingsphere.datasource.ds_master' is not valid:

Invalid characters: '_' // 非法

Bean: contentControlle

Reason: Canonical names should be kebab-case ('-' separated), lowercase alpha-numeric characters and must start with a lette // 应该用- 代替

Action:

Modify 'spring.shardingsphere.datasource.ds_master' so that it conforms to the canonical names requirements.