Christian Bongiorno
Christian Bongiorno

Reputation: 5648

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

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
    }
}

Upvotes: 0

Views: 307

Answers (1)

sidgate
sidgate

Reputation: 15244

You can use env

import org.springframework.core.env.get

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

Upvotes: 2

Related Questions