VBJ VBJ - 1 year ago 571
Java Question

Spring Mongodb- Could not instantiate bean class [java.util.List]: Specified class is an interface

my project is using Spring data mongodb. I was not having below error until i made an edit to one of the document that has a field with Array of Documents in it. It was working fine before but now I keep getting the below error.

The field i updated was impapps in the Projects POJO class. I am not sure how to clear this error tried different things but did not work out.

SEVERE: Servlet.service() for servlet [appServlet] in context with path [/mongodproject] threw exception [Request processing failed; nested exception is org.springframework.data.mapping.model.MappingInstantiationException: Could not instantiate bean class [java.util.List]: Specified class is an interface] with root cause
org.springframework.beans.BeanInstantiationException: Could not instantiate bean class [java.util.List]: Specified class is an interface
at org.springframework.beans.BeanUtils.instantiateClass(BeanUtils.java:101)
at org.springframework.data.convert.ReflectionEntityInstantiator.createInstance(ReflectionEntityInstantiator.java:60)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:232)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.read(MappingMongoConverter.java:212)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readValue(MappingMongoConverter.java:1008)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.access$100(MappingMongoConverter.java:75)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$MongoDbPropertyValueProvider.getPropertyValue(MappingMongoConverter.java:957)
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.getValueInternal(MappingMongoConverter.java:713)

Here are my POJO and Spring Repository class.

Project POJO Class

public class Project {
private String id;
private List<ImpactedApplications> impapps=new ArrayList<ImpactedApplications>();

ImpactedApplication POJO Class:

public class ImpactedApplications {

private String appId;
private List<ScriptsRepo> rep=new ArrayList<ScriptsRepo>();
private List<Artifacts> artifacts=new ArrayList<Artifacts>();
//getter and setters


Artifacts POJO Class

public class Artifacts {

private String artifactType;
private String documentLink;
private String artTestPhase;
private ArtifactsEnums artifactsNames;
private String startDate;
private String endDate;
private boolean peerReview;
private boolean busReview;
private boolean na;

Spring Repository classes

public interface ProjectRepository extends Repository<Project, String> {

Project findById(String id);
List<Project> findByYearAndReleaseMonthNoOrderByProjectNameDesc(String year,String month, Sort sort);
Project findByYearAndReleaseMonthNoAndId(String year, String month,String id);

Whenever i call the above methods i keep getting the exception.

Below is how my document is looking currently.

enter image description here

Answer Source

The impapps field in your document is not an array but a nested document. So if you change your List<ImpactedApplications> to a simple ImpactedApplications this should read fine.