Array index out of bounds: index0

Viewed 1225

I have the following code:

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);
}

it throws the following exception during server startup:

org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'planManagementController': Unsatisfied dependency expressed through field 'planService'; nested exception is org.springframework.beans.factory.UnsatisfiedDependencyException: Error creating bean with name 'planServiceImpl': Unsatisfied dependency expressed through field 'planRepository'; nested exception is org.springframework.beans.factory.BeanCreationException: Error creating bean with name 'planRepository': Invocation of init method failed; nested exception is java.lang.IndexOutOfBoundsException: Index: 0

If I remove this:

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

the server loads perfectly fine.

How to fix this?

1 Answers

When you combine MongoRepository and a customRepository (CustomPlanRepository) you have to implements CustomRepository interface (CustomPlanRepositoryImpl). Spring can't create this implementation.

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

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

     }
Related