springspring-bootkotlinspring-bean-dsl

Order of evaluation in Spring bean definition dsl for kotlin?


I wonder when environment method is being taken into account.

Considering following code:

bean { Bar(ref()) } // requires bean of type Foo
environment(
    { !activeProfiles.contains("local") },
    { ProdFoo() }))
environment(
    { activeProfiles.contains("local") },
    { bean<LocalFoo>() })

Sometimes I observed errors related with no bean of type Foo. Does it mean that environment is not evaluated as one of the first expressions?


Solution

  • The answer is plain simple - I've forgot to wrap ProdFoo() into bean{ ... }