Java 指定对象映射器后的无限递归
将以下代码添加到Java 指定对象映射器后的无限递归,java,spring,rest,Java,Spring,Rest,将以下代码添加到SpringBootRepositoryRestMVCCConfiguration子类后,出现无限递归错误: @Bean @Primary public com.fasterxml.jackson.databind.ObjectMapper objectMapper() { return new ObjectMapper(); } @Bean @Primary public ObjectMapper halObjectMapper() { return new
SpringBootRepositoryRestMVCCConfiguration
子类后,出现无限递归错误:
@Bean
@Primary
public com.fasterxml.jackson.databind.ObjectMapper objectMapper() {
return new ObjectMapper();
}
@Bean
@Primary
public ObjectMapper halObjectMapper() {
return new ObjectMapper();
}
错误是:
Servlet.service() for servlet [dispatcherServlet] in context with path []
threw exception [Request processing failed; nested exception is
org.springframework.http.converter.HttpMessageNotWritableException: Could not
write content: Infinite recursion (StackOverflowError) (through reference chain:
org.springframework.data.mongodb.core.mapping.CachingMongoPersistentProperty["owner"]-
>org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity["idProperty"]->org.springframework.data.mongodb.core.mapping.CachingMongoPersistentProperty["owner"]->org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity["idProperty"]->org.springframework.data.mongodb.core.mapping.CachingMongoPersistentProperty["owner"]->org.springframework.data.mongodb.core.mapping.BasicMongoPersistentEntity["idProperty"]->org.springframework.data.mongodb.core.mapping.CachingMongoPersistentProperty["owner"]->
在spring mongo存储库上执行GET时会发生这种情况。如果我删除
HaloObjectMapper()
行,它会工作。但是,我需要对其进行定义。如何解决这个问题?这两个映射器是否为同一类工作?我的意思是他们映射的是相同的包吗?@engma是的,我想是的