Pregunta

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.

enter image description here

¿Fue útil?

Solución

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.

Otros consejos

I have got the same exception :

Try to declare your field like this :

@Field("impapps")
ArrayList<ImpactedApplications> impapps = new ArrayList<ImpactedApplications>();

I don't like to do that but it works for me.

edit:

My issue was due to unwind operation during aggregation. It transform array (declared as List<> in my class) into object and then reflection doesn't work because spring was expecting a list.

use ArrayList someObjects instead of List someObjects.

It worked for me.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top