I have a set of entity classes and repository definitions and N databases, all of which have the schema. How can I instantiate N repositories pointing to each of the N databases.
@Entity
public class Student {
}
public interface StudentRepository extends JpaRepository< Student, Long> {
}
Making as many copies of repository interfaces as the number of databases (http://www.baeldung.com/spring-data-jpa-multiple-databases) and using dynamic datasource routing (http://spring.io/blog/2007/01/23/dynamic-datasource-routing/) were two solutions I found.
But, what I need is something like
@Component
public class Foo {
@Autowired
StudentRepository studentRepositoryForDatabase1;
@Autowired
StudentRepository studentRepositoryForDatabase2;
}
Is this feasible?