Issue
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
@Document(collection="releases")
public class Project {
@Id
private String id;
......
@Field("impapps")
private List<ImpactedApplications> impapps=new ArrayList<ImpactedApplications>();
.....getters/setters
}
ImpactedApplication POJO Class:
public class ImpactedApplications {
@Field("appid")
private String appId;
.....
@Field("repository")
private List<ScriptsRepo> rep=new ArrayList<ScriptsRepo>();
@Field("artifacts")
private List<Artifacts> artifacts=new ArrayList<Artifacts>();
//getter and setters
}
Artifacts POJO Class
public class Artifacts {
@Field("artifacttype")
private String artifactType;
@Field("documentlink")
private String documentLink;
@Field("arttestphase")
private String artTestPhase;
@Field("artifactname")
private ArtifactsEnums artifactsNames;
@Field("startdate")
private String startDate;
@Field("enddate")
private String endDate;
@Field("peerrev")
private boolean peerReview;
@Field("busrev")
private boolean busReview;
@Field("na")
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.
Solution
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.
Answered By - Oliver Drotbohm
Answer Checked By - David Marino (JavaFixing Volunteer)