bob*_*bob 8 java database jpa spring-data-jpa spring-boot
我有一个 Spring Boot 应用程序,当前使用 JPA 连接到单个数据库。其 application.properties 文件中的连接详细信息:
spring.datasource.url=jdbc:oracle:thin:@localhost:1522:orcl
spring.datasource.username=example
spring.datasource.password=example
spring.datasource.driver.class=oracle.jdbc.driver.OracleDriver
Run Code Online (Sandbox Code Playgroud)
现在我有一个想要连接的新数据库,因此我的应用程序现在连接了 2 个数据库。我可以使用 JDBC 连接它,在那里我必须手动编写连接代码。
我一直在寻找解决方案。有些处于休眠状态,具有多个配置文件。其他人正在使用 JDBC。
我尝试在 spring 文档中查找是否有在 application.properties 文件中定义多个数据源的规定,但找不到任何内容。
我想知道是否存在单独使用 JPA 的解决方案。谢谢你的时间。
MOn*_*key 10
请按照以下步骤操作:
\n\n将附加数据源配置添加到\napplication.properties。
在 application.properties 中将 SQL 方言设置为 \xe2\x80\x9cdefault\xe2\x80\x9d 以\n让 Spring 自动检测每个数据源的不同 SQL 方言
完整代码可以在这里找到,
\n\nhttps://github.com/jahe/spring-boot-multiple-datasources\nRun Code Online (Sandbox Code Playgroud)\n\n以上步骤取自本教程
\n\nhttps://medium.com/@joeclever/using-multiple-datasources-with-spring-boot-and-spring-data-6430b00c02e7\nRun Code Online (Sandbox Code Playgroud)\n\n希望这会有所帮助:)
\n| 归档时间: |
|
| 查看次数: |
27548 次 |
| 最近记录: |