我是spring和mongo db的新手 . 请为我的问题提出建议:我有这个用Spring编写的Web应用程序,它主要使用JPA作为数据库 . 我有一个多实体,然后我有多个存储库,用一些从数据库中获取数据的方法扩展JPARepository .

但现在我需要有第二个数据库,它必须是MongoDB . 一切都与JPA完全相同,但现在我有了一个新的存储库类,这次扩展了MongoRepository .

public interface CustomerRepository extends CrudRepository<Customer, Long> {

    List<Customer> findByLastName(String lastName);
}

public interface CustomerRepositoryMongo extends MongoRepository<Customer, Long> {

    List<Customer> findByLastName(String lastName);
}

所以现在我有两个类,CustomerRepository和CustomerRepositoryMongo . 1.首先,我必须在eclipse Ide中的mongodb中进行所有更改以及如何在eclipse IDE中配置mongodb . 2.如何在两个dbs之间轻松切换,如何指定使用哪个存储库? 3.我不知道如何实现这一点我也不能拥有同名的接口 . 4.我已经尝试了使用@profile注释的jpa方法,它的工作正常 . 但是要使用mongodb,我必须为所有具有@table,@ entity annotation的实体创建集合 . 所以我应该使用@document注释以及指定集合名称,因为我在查询中使用不同的名称 .