Springboot 中repository注册引发的包冲突问题。
这是我的MongoDBrepository
@EnableMongoRepositories
public interface RdyFileRepository extends MongoRepository<RdyFileEntity,String> {
RdyFileEntity findAllByIdAndDelete(String id, Integer isDelete);
}
这是我的Postgrsql对应的Repository
public interface PortalRepository extends BaseRepository<PortalEntity> {
PortalEntity findByTitle(String title);
List<PortalEntity> findAllByPid(UUID pid);
}
当他们在同一个包路径下时候,会出现错误
The bean 'rdyFileRepository', defined in com.redyear.cloud.server.repositoryMongo.File.
RdyFileRepository defined in @EnableMongoRepositories declared on MongoRepositoriesRegistrar.EnableMongoRepositoriesConfiguration, could not be registered.
A bean with that name has already been defined in com.redyear.cloud.server.repositoryMongo.File.RdyFileRepository defined in @EnableJpaRepositories declared on JpaRepositoriesRegistrar.
EnableJpaRepositoriesConfiguration and overriding is disabled.
它显示你的bean已经注册,其实是你的两个Jpa数据库实现冲突了,需要单独配置包扫描,
在主启动类配置
@EnableJpaRepositories(basePackages = {
"com.redyear.cloud.server.PortalrdyRepository"})
@EnableMongoRepositories(basePackages = {
"com.redyear.cloud.server.repositoryMongo.File.RdyFileRepository"})
问题解决。