Spring bean loading and test setup method order

40 Views Asked by At

Let's suppose there's a test like this:

@ActiveProfiles(value = "test")
@SpringBootTest(classes = AbcApplication.class, webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
class AbcTest extends Specification {

    @Autowired
    Foo foo

    @Autowired
    Bar bar

    void setup() {
        foo.setBar(bar)
    }

    def 'some test case'() {
        // ...
    }
}

I need to execute foo.setBar(bar) as early in the Spring application context's startup as possible. Foo and Bar are beans created through autoconfiguration, thus I can not instantiate them manually before Spring Boot startup is launched (i.e. using static block).

Anyone has an idea?

0

There are 0 best solutions below