springboot+jpa 实现不同数据库的多数据源配置(坑整理)

在搭建springboot+jpa 实现不同数据库的多数据源配置过程中会遇到很多坑,

SpringBoot引入mysql源的pom.xml等的配置:https://www.jianshu.com/p/2d92620dd979

首先是多数据源配置:https://blog.csdn.net/Birds_Cerebrum/article/details/81865352

这里最终要的一个坑是:Hibernate中的数据库方言配置,很多博文都没有此步,导致不同类型的数据库连接时依然用同一种数据库方言

:org.hibernate.dialect.Dialect            : HHH000400: Using dialect: org.hibernate.dialect.MySQL5Dialect

此日志就是数据库方言的内容,两个数据源都会加载各自的数据库方言。

数据库方言具体配置内容:https://blog.csdn.net/jialinqiang/article/details/8679171

配置方式:springboot+jpa 实现不同数据库的多数据源配置(坑整理)_第1张图片

此处配置的是两个方言 DB2和MySQL的。

2..配置:application.yml

springboot+jpa 实现不同数据库的多数据源配置(坑整理)_第2张图片

此配置时在spring节点下的配置。 如果在URL后面加入了编码方式可能会引起错误:

Bean method 'dataSource' not loaded because @ConditionalOnProperty (spring.datasource.type) did not

3.No Identifier specified for entity:由于结合的是jpa,所以有些这是需要做:

这里有引入JPA的配置方式:https://www.jianshu.com/p/0a064581bf60

以下是解决上面报错问题的地址:https://blog.csdn.net/qq_38584262/article/details/85275513

4.Field xxx in xxx.xxx.xxx required a bean of type 'xxx.xxx.xxx' that could not be found.:

这个问题可以用两个方式解决,具体地址:http://www.sohu.com/a/241622266_418879

 

你可能感兴趣的:(环境搭建,springboot数据源配置)