Hello! :wave: I’m hitting a problem with condition...
# spring
Hello! 👋 I’m hitting a problem with conditional bean creation order - I’m writing custom bean registrar to generate and register some beans based on the configuration properties and I provide some default beans as a fallback. Basically • I got an annotation for explicit opt-in where I import my registrar and fallback config • registrar is environment aware so it can bind my properties and uses factory bean to create target beans (e.g.
is application context aware and it attempts to retrieve
from context (e.g. using
• within a
I’m explicitly creating
in a configuration class So my problem is that conditional logic (i.e.
) is evaluated BEFORE attempting to create the
in test configuration…. Sample code in the thread. Any ideas what I might be missing?
Copy code
@Import(MyBeanRegistrar::class, MyFallbackConfiguration::class)
annotation class EnableMyAutoConfiguration

class MyFallbackConfiguration {

    fun fallbackBean(someBean: SomeBean): FallbackBean = DefaultFallbackBean(someBean)

@SpringBootTest(classes = [MyConfigurationIT.MyTestConfiguration::class])
class MyConfigurationIT {

    class MyTestConfiguration {

        fun someBean(): SomeBean = SomeBean()   // <== this gets created AFTER conditional evaluation

    fun `context loads`() {
if anyone is looking for the similar problem -> I solved the issue by making
a spring auto configuration (i.e. configuring it in
and removing the explicit import from the annotation)