java - Spring Data Rest not working——寻找无限递归错误的根源

标签 java spring spring-mvc spring-boot spring-data-rest

简而言之

我需要找到显示在 spring data rest 中的错误消息的根本原因。如何通过查看一般错误消息找到我应该放置 @JsonIgnore@RestResource(exported = false) 的确切位置?

详细说明

我用 spring data rest 嵌入了我的 Spring 应用程序。尽管有很多实体和存储库,但我只希望通过 rest 公开很少的实体。其中一个实体是 user

但我收到以下错误消息。 我怎样才能深入到我能真正找到这个一般错误消息的根本原因的地方?

Could not write content: Infinite recursion (StackOverflowError) (through reference chain: org.springframework.hateoas.Resources["_embedded"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: org.springframework.hateoas.Resources["_embedded"])

存储库

@RepositoryRestResource(collectionResourceRel = "system-users", itemResourceRel = "system-user", path = "system-users")
public interface UserRepository extends CrudRepository<User, Long>, DatatablesCriteriasRepository<User>{

    @RestResource(exported = false)
    @Query("SELECT u FROM User u INNER JOIN u.roles role WHERE role.role in :roles")
    Iterable<User> findByRoles(@Param("roles") String... roles);

    @RestResource(exported = false)
    @Query("SELECT u FROM User u WHERE u.username = :username")
    User findByUsername(@Param("username") String username);
    ...
    ...
}

型号

@Entity
@Table(name = "system_user_tab")
public class User{
...
...

我知道通过使用 @JsonIgnore, @RestResource(exported = false) 我可以尝试消除这个问题。但是我需要通过查看此错误消息来了解如何理解我必须使用这些注释的确切位置。

最佳答案

您可以在较新版本的 Spring Data Rest 2.4.0.RELEASE 中执行此操作:

Could not write content: Infinite recursion (StackOverflowError) (through reference chain: org.springframework.hateoas.PagedResources[\"_embedded\"]->java.util.UnmodifiableMap[\"payment\"]->java.util.ArrayList[0]->org.springframework.data.rest.webmvc.json.ProjectionResource[\"content\"]->$Proxy153[\"subject\"]); nested exception is com.fasterxml.jackson.databind.JsonMappingException: Infinite recursion (StackOverflowError) (through reference chain: org.springframework.hateoas.PagedResources[\"_embedded\"]->java.util.UnmodifiableMap[\"payment\"]->java.util.ArrayList[0]->org.springframework.data.rest.webmvc.json.ProjectionResource[\"content\"]->$Proxy153[\

它将是字段 subject

关于java - Spring Data Rest not working——寻找无限递归错误的根源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30682797/

相关文章:

java - 使用带有 Struts2 的 Spring Security 的表单的动态 URL 访问权限?

java - 在java中迭代2个映射

java - 如何在响应api之前对数据进行分组

java - spring和spring security有没有什么好的入门电子资料或者网站?

使用 spring webMVC 和 spring security 进行 ajax 登录

java - Maven 项目 - Spring MVC 错误

java - Selenium Java : Unable to upload a file via custom upload

java - 是否可以使用 junit 和 mockito 创建嵌套单元测试?

java - 获取Spring WebClient请求的状态码

java - BeanFactory实现