stackoverflow错误?

xxls0lw8  于 2021-07-16  发布在  Java
关注(0)|答案(0)|浏览(367)

我正在从事一个spring boot mvc项目,在单元测试crud控制器时遇到以下错误:

java.lang.StackOverflowError
at java.base/java.lang.Throwable.getOurStackTrace(Throwable.java:840)
at java.base/java.lang.Throwable.getStackTrace(Throwable.java:832)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:55)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:60)

java.lang.StackOverflowError
at java.base/java.lang.AbstractStringBuilder.append(AbstractStringBuilder.java:834)
at java.base/java.lang.StringBuilder.append(StringBuilder.java:247)
at ch.qos.logback.classic.pattern.ThrowableProxyConverter.subjoinSTEPArray(ThrowableProxyConverter.java:216)
at ch.qos.logback.classic.pattern.ThrowableProxyConverter.recursiveAppend(ThrowableProxyConverter.java:161)
at ch.qos.logback.classic.pattern.ThrowableProxyConverter.recursiveAppend(ThrowableProxyConverter.java:168)

这里有一个控制器单元测试,其他的遵循相同的逻辑。

@Autowired
private MockMvc mockMvc;

@MockBean
private PessoaRepository pessoaRepository;

@Test
public void deletarPessoa_quandoDelete() throws Exception {
    Pessoa pessoa = new Pessoa();
    pessoa.setNome("Test Nome");
    pessoa.setId(89L);
    doNothing().when(pessoaRepository).delete(pessoa);
    mockMvc.perform(delete("/pessoas/" + pessoa.getId().toString())
            .contentType(MediaType.APPLICATION_JSON))
            .andExpect(status().isNoContent());
}

这会是什么?我不知道我为什么会犯这个错误。
编辑:这里是控制器,它基本上要求repo删除一个pessoa对象

@DeleteMapping("/{id}")
@ResponseStatus(HttpStatus.NO_CONTENT)
public void deletar(@ApiParam(value = "ID", example = "1") @PathVariable Long id) {
    Pessoa pessoaDeletada = pessoaRepository.getOne(id);
    pessoaRepository.delete(pessoaDeletada);
}

暂无答案!

目前还没有任何答案,快来回答吧!

相关问题