首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >不支持的采集接口

不支持的采集接口
EN

Stack Overflow用户
提问于 2018-10-07 21:01:14
回答 1查看 655关注 0票数 0

我正在将一个遗留应用程序移植到MongoDB,因此我尝试重用现有的POJO。我设法成功地将数据持久化到MongoDB中,但是当我读取文档时,它失败了,出现了以下异常:

代码语言:javascript
复制
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]

有没有办法解决这个问题?

EN

回答 1

Stack Overflow用户

发布于 2018-10-07 21:22:38

您需要确保IObservableList的类型(collectionType)满足Spring代码实现的逻辑:

代码语言:javascript
复制
    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());
        }
    }

请参阅https://github.com/spring-projects/spring-framework/blob/5.0.x/spring-core/src/main/java/org/springframework/core/CollectionFactory.java

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/52688738

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档