作者热门文章
- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我正在尝试构建一个 MongoRepository
,它允许根据类成员查找文档。
这是我的缩写数据对象:
public class Example<T extends SomeType> {
private String id;
private Class<T> dataClass;
}
这是我的存储库:
public interface ExampleRepository extends MongoRepository<Example<? extends SomeType>, String> {
<T extends SomeType> Example<T> findByDataClass(Class<T> dataClass);
}
以下是我如何保存 Example
实例的示例:
@Autowired
private ExampleRepository examples;
void someMethod() {
examples.save(new Example<>(null, SomeConcreteType.class));
}
当我尝试启动我的应用程序时,出现异常:
org.bson.codecs.configuration.CodecConfigurationException: Can't find a codec for class java.lang.Class.
我不知道这是否相关,但我正在使用 Fongo 在本地构建内存数据库。
我该如何解决这个问题?
最佳答案
这是不可能实现的。如果您尝试保存,您将收到相同的错误消息。
Can't find a codec for class java.lang.Class
这是因为,Mongo 不知道这种数据类型。查看此链接以了解 Mongo 支持的数据类型。 http://mongodb.github.io/mongo-java-driver/3.0/bson/documents/
关于java - 如何使用 findByClassLiteral 查询构建自定义 MongoRepository,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50872810/
我正在尝试构建一个 MongoRepository,它允许根据类成员查找文档。 这是我的缩写数据对象: public class Example { private String id; pr
我是一名优秀的程序员,十分优秀!