Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

@SpringBootTest annotation resulting in StackOverflowError

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:

@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:

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)

...and so on.

contextLoads() is failing like this as well.

I tried to add several logging dependencies, remove Lombok from my code, look for this error but with no success. Only thing related to this issue was this: https://jira.qos.ch/browse/LOGBACK-1454 But I found no solution there. This is my first question, so please do not be too hard. I just want to test my application, but I ran out of ideas how to solve this...thank you and have a nice day.

EDIT: https://github.com/matyzatka/BankAppBackend is the project, if you need to see the code :)

like image 973
Matouš Zátka Avatar asked Nov 16 '25 12:11

Matouš Zátka


1 Answers

To fix it, we just deleted these lines (from security config):

// DELETE THIS:
@Bean
public AuthenticationManager authenticationManagerBean() throws Exception {
    return configuration.getAuthenticationManager();
}

Plus (deleted) "orphaned code", imports, etc...:

//"orphaned":
private final AuthenticationConfiguration configuration;

public SecurityConfiguration(AuthenticationConfiguration configuration) {
    this.configuration = configuration;
}

We were lucky, that indeed nothing in our context needed an "exposed AuthenticationManager bean"... Otherwise we would act, as proposed by:

https://spring.io/blog/2022/02/21/spring-security-without-the-websecurityconfigureradapter (InMemory, Global, Local...)

like image 146
xerx593 Avatar answered Nov 18 '25 20:11

xerx593



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!