我正在将旧版应用程序移植到MongoDB,因此,我试图重用现有的POJO。我成功地将数据持久保存在MongoDB中,但是当我阅读文档时,它失败了,但出现以下异常:
Caused by: java.lang.IllegalArgumentException: Unsupported Collection interface: com.company.product.dto.datatypes.IObservableList
at org.springframework.core.CollectionFactory.createCollection(CollectionFactory.java:191) ~[spring-core-5.0.7.RELEASE.jar:5.0.7.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readCollectionOrArray(MappingMongoConverter.java:960) ~[spring-data-mongodb-2.0.9.RELEASE.jar:2.0.9.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readValue(MappingMongoConverter.java:1385) ~[spring-data-mongodb-2.0.9.RELEASE.jar:2.0.9.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter$MongoDbPropertyValueProvider.getPropertyValue(MappingMongoConverter.java:1334) ~[spring-data-mongodb-2.0.9.RELEASE.jar:2.0.9.RELEASE]
at org.springframework.data.mongodb.core.convert.MappingMongoConverter.readProperties(MappingMongoConverter.java:335) ~[spring-data-mongodb-2.0.9.RELEASE.jar:2.0.9.RELEASE]
有没有办法解决这个问题?
答案 0 :(得分:0)
您需要确保collectionType
的类型(IObservableList
)满足Spring代码实现的逻辑:
if (collectionType.isInterface()) {
if (Set.class == collectionType || Collection.class == collectionType) {
return new LinkedHashSet<>(capacity);
}
else if (List.class == collectionType) {
return new ArrayList<>(capacity);
}
else if (SortedSet.class == collectionType || NavigableSet.class == collectionType) {
return new TreeSet<>();
}
else {
throw new IllegalArgumentException("Unsupported Collection interface: " + collectionType.getName());
}
}