如何为存储库设置特定的DataSource? [英] How to set a specific DataSource for a Repository?

查看:97
本文介绍了如何为存储库设置特定的DataSource?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以将特定的 DataSource 分配给 @Repository

Is it possible to assign a specific DataSource to a @Repository?

我想创建一个测试环境,一般我想使用test-datasource,但是一些 CrudRepository 应该在不同的地方运行DB(生产数据库;只读操作)。

I'd like to create a test environment where in general I want to use the test-datasource, but a few CrudRepository should operate on a different DB (the production DB; read-only operations).

我可以告诉spring哪个数据源用于显式存储库吗?

Can I tell spring which datasource to use for a repository explicit?

public interface MyRepository扩展CrudRepository< Customer,Long> {}

推荐答案

@EnableJpaRepositories 是你的问题的答案。根据非正式文档,这应该与 CrudRepository 一起使用。

@EnableJpaRepositories is the answer to your question. This should work with CrudRepository according to the informal documentations.

请参阅此详细教程,了解如何执行此操作。我没有花时间在这里发布代码,因为你可以直接在其中更清楚地提及它。

Refer this detail tutorial on how to do this. I didn't put my effort to post the codes here as you may directly refer it much clearer in it.

指向教程的链接......

这篇关于如何为存储库设置特定的DataSource?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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