当 MongoDB DBRef lazyness 设置为 true 时, java.lang.IllegalArgumentException 被抛出

When MongoDB DBRef lazyness is set to true, java.lang.IllegalArgumentException is throw

我有以下 class:

@Document(collection = "T_FOO")
public class Foo implements Serializable {

    @Field
    private String name;

    @Field
    private String observations;

    @DBRef
    @Field
    private Foo[] parents;

}

本次测试成功者:

@Test
    public void testFooWithParents() throws Exception {
        //mock User
        User user = new User(); user.setLogin("admin");
        when(userService.getUserWithAuthorities()).thenReturn(user);

        // Create Father
        restFooMockMvc.perform(post("/app/rest/foos")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJson(fooFather)))
                .andExpect(status().isOk());
        // Create Mother
        restFooMockMvc.perform(post("/app/rest/foos")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJson(fooMother)))
                .andExpect(status().isOk());

        foo.setParents(new Foo[]{fooFather, fooMother});

        // Create Foo
        restFooMockMvc.perform(post("/app/rest/foos")
                .contentType(TestUtil.APPLICATION_JSON_UTF8)
                .content(TestUtil.convertObjectToJson(foo)))
                .andExpect(status().isOk());

        // Read Foo
        MvcResult result = restFooMockMvc.perform(get("/app/rest/foos/{id}", DEFAULT_ID))
                .andExpect(status().isOk())
                .andExpect(content().contentType(MediaType.APPLICATION_JSON))
                .andExpect(jsonPath("$.id").value(DEFAULT_ID))
                .andExpect(jsonPath("$.name").value(DEFAULT_NAME.toString()))
                .andExpect(jsonPath("$.observations").value(DEFAULT_OBSERVATIONS))
                .andExpect(jsonPath("$.parents[0].id").value(FATHER_ID))
                .andExpect(jsonPath("$.parents[1].id").value(MOTHER_ID))
                .andReturn();

        String content = result.getResponse().getContentAsString();
    }

当我将父数组设置为 lazy = true 时,出现了这个异常:

    org.springframework.web.util.NestedServletException: 
Request processing failed; nested exception is java.lang.IllegalArgumentException:  
Cannot subclass final class class [Lorg.domain.Foo;

这是在我请求 Foo 子 ("Read Foo") 时抛出的。 Spring 无法再次重建对象是怎么回事?

最好的, 佩德罗

延迟加载 Spring 数据 MongoDB 中的 Db-Refs 仅当 属性 的类型为非最终 class 或接口时才受支持,因为我们需要能够为其创建 JDK 或 CGLib 代理。不支持数组。我创建了 https://jira.spring.io/browse/DATAMONGO-1157 来跟踪这个。