Home > Mobile >  How to inject @Value into a bean using kotlin beans DSL
How to inject @Value into a bean using kotlin beans DSL

Time:11-10

I need to inject some config values into a bean, and I am trying to use the new dsl for kotlin. Basically, I need the java equivalent of the following, but for kotlin bean DSL


public Thing myThing(@Value("${foo}") String foo) {
   return new Thing(foo)
}

in Kotlin DSL:

val beans = beans {
    bean {
      Thing("????? How to get foo") // I need @Value("${foo}") here
    }
}

CodePudding user response:

You can use env

import org.springframework.core.env.get

val beans = beans {
    bean {
      Thing(env["foo"]) 
    }
}
  • Related