Spring Boot 2.6.6 fails to run tests, but is able to load application

Viewed 39

I'm currently building an Spring boot application that is meant as a middle-man between an SPA and another platform. When started normally, the applications runs, but tests always fails for some reasons.

When just adding a test case to check if the context is loaded (like described here and the code piece below), the tests automatically fail and cannot be loaded.

    package com.company.it.gdppwaapi;
    
    import org.junit.jupiter.api.Test;
    import org.springframework.boot.test.context.SpringBootTest;
    
    @SpringBootTest
    class GdpPwaApiApplicationTests {
        @Test
        void contextLoads() {
    
        }
    }

The resulting error message that I get is as follows:

    java.lang.StackOverflowError
        at java.util.IdentityHashMap.hash(IdentityHashMap.java:297)
        at java.util.IdentityHashMap.put(IdentityHashMap.java:428)
        at java.util.Collections$SetFromMap.add(Collections.java:5515)
        at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:82)
        at ch.qos.logback.classic.spi.ThrowableProxy.<init>(ThrowableProxy.java:89)
        ...

The last 2 lines are continually repeated in the logs, so I've shorten it

When I use IntelliJ's debugger, I also see that the following exception is thrown from the void contextLoads() function: [![IntelliJ's Debugger output][1]][1]

I've tried the following things already:

  • Setting the SpringBootTest annotation as follows:
  @SpringBootTest(classes = GdpPwaApiApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
  • Extending the Application context with @ExtendWith(SpringExtension.class) in the test file
  • Adding the logback dependencies explicitly (As some other projects in our company explicitly state that in the pom.xml)
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-classic</artifactId>
    </dependency>
    <dependency>
        <groupId>ch.qos.logback</groupId>
        <artifactId>logback-core</artifactId>
    </dependency>
  • Adding the component scan that is in the main startup class to the test class.

Has somebody had a similar solution like this and found a way to resolve it? Thank you!

pom.xml Dependencies

    <dependencies>
        <!-- Spring Boot -->
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-web</artifactId>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-test</artifactId>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springdoc</groupId>
            <artifactId>springdoc-openapi-ui</artifactId>
            <version>1.6.4</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security.oauth</groupId>
            <artifactId>spring-security-oauth2</artifactId>
            <version>2.2.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework.security</groupId>
            <artifactId>spring-security-jwt</artifactId>
            <version>1.0.9.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-aspects</artifactId>
            <scope>compile</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework.boot</groupId>
            <artifactId>spring-boot-starter-actuator</artifactId>
        </dependency>
    </dependencies>

Main startup class

    package com.company.it.gdppwaapi;
    
    import org.springframework.boot.SpringApplication;
    import org.springframework.boot.autoconfigure.SpringBootApplication;
    import org.springframework.context.annotation.ComponentScan;
    
    @SpringBootApplication
    @ComponentScan({"com.company.it.security", "com.company.it.gdppwaapi"})
    public class GdpPwaApiApplication {
    
        public static void main(String[] args) {
            SpringApplication.run(GdpPwaApiApplication.class, args);
        }
    }

Main test class

    package com.company.it.gdppwaapi;
    
    import org.junit.jupiter.api.Test;
    import org.springframework.boot.test.context.SpringBootTest;
    
    @SpringBootTest
    class GdpPwaApiApplicationTests {
        @Test
        void contextLoads() {
    
        }
    }

Update 1

After searching for a while, we found out that the security package searches for a logback configuration file. While this has resolved the StackOverflowException, this revealed the underlying error that was being returned:

Caused by: java.lang.IllegalStateException: Failed to unwrap proxied object
Caused by: java.lang.IllegalStateException: Failed to unwrap proxied object
Caused by: java.lang.IllegalStateException: Failed to unwrap proxied object
Caused by: java.lang.IllegalStateException: Failed to unwrap proxied object
Caused by: java.lang.IllegalStateException: Failed to unwrap proxied object
Caused by: java.lang.IllegalStateException: Failed to unwrap proxied object
Caused by: java.lang.IllegalStateException: Failed to unwrap proxied object

From what I read around the web, it could be Mockito related. Any help on what is could be would be appreciated. [1]: https://i.stack.imgur.com/zqh43.png

0 Answers
Related