是否可以在单个 Spring 引导应用程序中同时使用 Spring Data R2DBC 和 Spring Data JPA? [英] Is it possible to use both Spring Data R2DBC and Spring Data JPA in a single Spring boot application?

查看:38
本文介绍了是否可以在单个 Spring 引导应用程序中同时使用 Spring Data R2DBC 和 Spring Data JPA?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个应用程序,它使用 Spring 数据 JPA 和 hibernate envers 进行数据库审计.由于 R2DBC 尚不支持审计,是否可以在单个应用程序中结合使用两者?

I have an application which is using Spring data JPA and hibernate envers for db auditing. Since R2DBC doesn't support auditing yet, is it possible to use combination of both in a single application?

如果是,Plan 是使用 Spring Data JPA 进行插入、更新和删除操作,这样所有的 DB 审计都将由 hibernate envers 处理.并使用 R2DBC 进行反应式非阻塞 API 来读取数据.

If yes, Plan is to use Spring Data JPA for insert, update and delete operations, so that all DB auditing will be handled by hibernate envers. And use R2DBC for reactive non-blocking API's to read data.

如果没有,是否有关于如何同时实现响应式 API 和审计的建议?

If no, Is there any suggestions on how to achieve both reactive API's and auditing?

推荐答案

  1. Spring 通过 @EnableR2dbcAuditing检查我的例子.

在反应式应用程序中混合 JPA 也是可能的,我有 一个示例 演示在反应式应用程序中运行 JPA,但未在其中添加 r2dbc.

Mix JPA in a reactive application is also possible, I have an example to demo run JPA in a reactive application, but not added r2dbc in it.

对于您的计划,更好的解决方案是在数据库拓扑上应用 cqrs 模式,为您的应用程序使用数据库集群.

For your plan, a better solution is applying the cqrs pattern on the database topology, use database cluster for your application.

  • 用于应用更改的 JPA,使用主/主数据库接受修改,并将更改同步到辅助/从数据库.
  • r2dbc 查询如您所愿,使用辅助/从数据库进行查询.
  • 在前端使用网关来提供查询和命令服务.

更新:我创建了一个示例来演示 JPA 和 R2dbc 在单个 webflux 应用程序中共存.但我不建议在实际应用中使用它.如果您确实需要,请考虑上面的第三个解决方案.

Update: I have created a sample to demo JPA and R2dbc coexistence in a single webflux application. But I do not suggest using it in real-world applications. Consider the 3rd solution above if you really need it.

这篇关于是否可以在单个 Spring 引导应用程序中同时使用 Spring Data R2DBC 和 Spring Data JPA?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆