I would like to test some services in my application, but when I use @SpringBootTest annotation, they result in StackOverflowError
To start with, I am using JUnit5 and I tried to create some basic test like:(我想在我的应用程序中测试一些服务,但是当我使用@SpringBootTest注释时,它们会导致 StackOverflowError。首先,我正在使用JUnit5,并尝试创建一些基本测试,例如:)
@Test
void onePlusOneShouldBeTwo() {
int one = 1;
assertEquals(2, one + one);
}
and this one works fine.(这个工作正常。)
But for more complex tests I need to use @SpringBootTest and no matter what the test looks like, error is still:(但是对于更复杂的测试,我需要使用@SpringBootTest无论测试是什么样子,错误仍然存在:)
java.lang.StackOverflowError
at java.base/java.lang.StackTraceElement.of(StackTraceElement.java:541)
at java.base/java.lang.Throwable.getOurStackTrace(Throwable.java:838)
at java.base/java.lang.Throwable.getStackTrace(Throwable.java:830)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:79)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
堆栈溢出错误
查了很多教程都说是logback
版本或者配置
经过大佬的指正发现是用到security config
, 在不需要登录验证的项目模块中需要删除掉以下代码
// DELETE THIS:
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
return configuration.getAuthenticationManager();
}
或者
文章来源:
https://stackoverflow.com/questions/73929257/springboottest-annotation-resulting-in-stackoverflowerror