目前spring数据有多个数据库支持(mysql、cassandra、mongo..非常大的列表),但是我想从头开始添加我的自定义存储库,比如在spring数据中添加自定义数据库支持。我不想扩展任何现有的存储库,而是想为我的自定义数据源创建一个并行存储库结构。看看当前的实现,它看起来像是一项乏味的任务。如果有人能以最低要求帮助我做到这一点,那就太好了。
最佳答案
您可以创建一个存储库注释 bean,您将在其中注入(inject) 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 存储库的自定义实现
关于spring-boot - 在 Spring Data 中添加新的 DB 支持,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/62382464/