【问题标题】:Adding new DB support in spring data在 Spring Data 中添加新的 DB 支持
【发布时间】:2020-10-04 12:36:14
【问题描述】:

目前 spring 数据有多个数据库支持(mysql、cassandra、mongo.. 非常大的列表),但是我想从头开始添加我的自定义存储库,比如在 spring 数据中添加自定义数据库支持。我不想扩展任何现有的存储库,而是想为我的自定义数据源创建一个并行存储库结构。看看当前的实现,它看起来像是一项繁琐的任务。如果有人能以最低要求帮助我,那就太好了。

【问题讨论】:

  • 您可能需要使用相关代码添加更多详细信息才能获得满足您要求的答案

标签: spring-boot spring-data spring-repositories


【解决方案1】:

您可以创建一个存储库注释 bean,您将在其中注入 EntityManager 或具有类似行为的适当 bean,具体取决于您使用的数据库类型。

@Repository
public class MyCustomRepositoryImpl implements MyCustomRepository {

@Autowired
private EntityManager entityManager;

//the methods that you are going to create.

}

更多详情见:

https://docs.spring.io/spring-data/data-commons/docs/1.6.1.RELEASE/reference/html/repositories.html Chapter: 1.3 Spring Data 仓库的自定义实现

【讨论】:

  • 这不是我在看的,我想添加完整的功能,例如:其他人应该只扩展接口并在所需实体上添加@Repository 功能。其他一切都应该自动配置。例如,当我们与新数据库集成时,我们只更改 baseRepositotry 类型。例如:JpaRepository、CassandraRepository 等
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2014-07-06
  • 2023-03-10
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2023-03-24
  • 2017-12-14
相关资源
最近更新 更多