Is it possible to assign a specific DataSource
to a @Repository
?
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).
Can I tell spring which datasource to use for a repository explicit?
public interface MyRepository extends CrudRepository<Customer, Long> {}
Advertisement
Answer
@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.