猿问

使用 mariaDB 在 Spring-Boot 中实现多个数据库

我需要知道从多个数据库访问存储库和实体类的简单步骤。例如:我有用户表DB1和电子邮件在DB2必须从单一的服务请求访问。


数据库 1

spring.datasource.url = jdbc:mysql://localhost:3306/dbName1?useSSL=false

spring.datasource.username = user

spring.datasource.password = password

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect

spring.jpa.hibernate.ddl-auto = update

数据库 2

spring.datasource.url = jdbc:mysql://localhost:3306/dbName2?useSSL=false

spring.datasource.username = user

spring.datasource.password = password

spring.jpa.properties.hibernate.dialect = org.hibernate.dialect.MySQL5InnoDBDialect

其他属性

spring.jpa.properties.hibernate.jdbc.batch_size=20

spring.jpa.properties.hibernate.order_inserts=true

spring.jpa.properties.hibernate.order_updates=true

spring.jpa.properties.hibernate.jdbc.batch_versioned_data=true

spring.servlet.multipart.max-file-size=100MB 

spring.servlet.multipart.max-request-size=100MB


www说
浏览 295回答 3
3回答

牛魔王的故事

(不是直接回答。)如果您将使用普通英语以外的文本,请考虑以下设置:休眠 XML:<property name="hibernate.connection.CharSet">utf8mb4</property><property name="hibernate.connection.characterEncoding">UTF-8</property><property name="hibernate.connection.useUnicode">true</property>连接网址:db.url=jdbc:mysql://localhost:3306/db_name?useUnicode=true&character_set_server=utf8mb4

米脂

@Table(name="tablename",&nbsp;catalog="db2")为我工作
随时随地看视频慕课网APP

相关分类

Java
我要回答