简体   繁体   中英

Failed to instantiate java.util.List using constructor NO_CONSTRUCTOR with arguments ]

i am getting

Failed to instantiate java.util.List using constructor NO_CONSTRUCTOR with arguments ] with root cause
org.springframework.beans.BeanInstantiationException: Failed to instantiate [java.util.List]: Specified class is an interface

this exception while updating the mongodb nested document.

the problem is the same as it is dicscuseed it this link

http://forum.spring.io/forum/spring-projects/data/nosql/724397-mapping-exception-with-mongodb-aggregation-framework

but still no clue how to solve it. anyone gone thorugh this??

I just had the same problem and solved it thanks to: Mongo db java unwind operation in aggregate query throwing exception

When in the aggregation the unwind happened, the results are flattened so in my case I had a class like:

MyClass {
   String _id;
   List<SomeObject> objectList;
}

The exception occurs because of the flattening, the results on my list object instead of coming up in an array, now are just a single object because of the $unwind.

What I did to fix this was to create the same class without the list:

MyClassAggregationResult {
  String _id;
  SomeObject objectList;
}

This way the results are mapped correctly.

Hope this works for you as well.

change to as below it should work

String _id;

SomeObject objectList;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM