简体   繁体   中英

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

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...)

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM