首页 > 解决方案 > 数组索引超出范围:index0

问题描述

我有以下代码:

public interface CustomPlanRepository {
    void plansUpdate(Query query,Update update,Class classname,String Collection);  
}

@Repository
public interface PlanRepository extends MongoRepository<Plan, 
                                          Serializable>,CustomPlanRepository{

    Plan findById(String id);
}

它在服务器启动期间引发以下异常:

org.springframework.beans.factory.UnsatisfiedDependencyException:创建名为“planManagementController”的bean时出错:通过字段“planService”表示不满足的依赖关系;嵌套异常是 org.springframework.beans.factory.UnsatisfiedDependencyException:创建名称为“planServiceImpl”的 bean 时出错:通过字段“planRepository”表示不满足的依赖关系;嵌套异常是 org.springframework.beans.factory.BeanCreationException:创建名为“planRepository”的 bean 时出错:调用 init 方法失败;嵌套异常是 java.lang.IndexOutOfBoundsException: Index: 0

如果我删除这个:

void plansUpdate(Query query,Update update,Class classname,String Collection);

服务器加载得很好。

如何解决这个问题?

标签: javaspringspring-data-jpaspring-data

解决方案


当您结合 MongoRepository 和 customRepository (CustomPlanRepository) 时,您必须实现 CustomRepository 接口 (CustomPlanRepositoryImpl)。Spring 无法创建此实现。

public class CustomPlanRepositoryImpl implements CustomPlanRepository {
    @Autowired
    private MongoTemplate mongoTemplate;

     void plansUpdate(Query query,Update update,Class classname,String Collection){
    ....

     }

推荐阅读